Warning regarding not using bundler when running guard init - ruby-on-rails

In my Rails app am getting this warning when running guard init rspec:
Warning: you have a Gemfile, but you're not using bundler or
RUBYGEMS_GEMDEPS
14:54:15 - INFO - Writing new Guardfile to
/home/ubuntu/railsprojects/sillyfish/Guardfile 14:54:16 - INFO - rspec
guard added to Guardfile, feel free to edit it
I don't understand why it's showing. Is it okay to ignore this warning?
Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.4'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'rspec-rails', '3.3.3'
gem 'guard-rspec', require: false
gem 'spring-commands-rspec'
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :test do
gem 'capybara', '2.5.0'
end
#custom gems
gem 'puma'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'devise', '~> 3.5.2'

If you run guard init rspec, it will use the globally installed guard-rails. To run the one installed through your Gemfile, use bundle exec guard init rspec. This is also what is recommended in the documentation.
From the README:
It's important that you always run Guard through Bundler to avoid errors.
So it's probably best to take this warning seriously, to avoid issues down the line.

A more technical answer:
There are 3 ways gems can be selected for your Ruby (or Rails) projects:
As they are installed on your system (by looking at environment variables such as $GEM_HOME), e.g. guard init rspec will look for guard and guard-rspec in your $GEM_HOME. Usually RubyGems will use the latest installed versions you have installed (not always what you'll want).
If you have Bundler, bundle exec guard init rspec will cause your gems to be loaded in versions listed in your Gemfile.lock. This also allows you to load gems directly from other folders (anywhere using :path option in your Gemfile) bundled with the app (e.g. .bundle directory) or even downloaded and updated from GitHub (using :github, :branch, etc. options).
If you have a recent version of RubyGems, it can also load your gems from a Gemfile.lock. But only if you have the $RUBYGEMS_GEMDEPS environment properly set up. It works like Bundler (it reads your Gemfile.lock), except it doesn't have all the features (like loading gems from a GitHub repository).
In general, if your project has a Gemfile, it's best to use Bundler, because it makes sure all the versions of all gems are matched up to what you expect.

Related

Cannot find gem even though bundle reports it is installed

I am attempting to install kaminari, but Rails cannot find it or a dependency (I've run into both - currently dependency):
∴ bundle exec rails g kaminari:config
Could not find i18n-1.8.4 in any of the sources
Run `bundle install` to install missing gems.
This is despite it being installed:
∴ bundle info i18n
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
* i18n (1.8.4)
Summary: New wave Internationalization support for Ruby
Homepage: https://github.com/ruby-i18n/i18n
Path: /Users/shawn/.rvm/gems/ruby-2.6.3#refstats/gems/i18n-1.8.4
I first attempted to delete Gemfile.lock. Same result. Then I deleted the refstats gemset and recreated it. Same result. Then I tried bundle install --force and got same result.
I've tried both gem 'kaminari', '~> 1.2' and gem 'kaminari' in my Gemfile.
Any suggestions?
EDIT:
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3', '~> 1.4'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'devise', '~> 4'
gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Edit 2:
∴ cat .ruby-version
ruby-2.6.3
I have no .ruby-gemset, but my console is reporting I'm using the right one:
12:36:50 shawn#macbook-pro:~/Documents/uga/refstats (git:master:547a0b4) ruby-2.6.3#refstats
∴
EDIT 3:
Well, the gremlin has disappeared, though I cannot say why. This is what I did:
1) Created new test rails app
2) Bundle install in new gemset
3) Added kaminari to Gemfile
4) Bundle install
5) Generated kaminari config successfully
6) Switch to non-working app, but forget to switch gemset, putting me in rvm with no gemset. Don't notice.
7) Bundle install
8) Notice things get installed, including kaminari. Notice I'm on wrong gemset.
9) Switch to correct gemset.
10) Bundle install (which installs nothing)
11) Generate kaminari config successfully
I really cannot say why it started working, unless installing to the rvm root had some effect. But that's what I did, and it's all working now. Thanks for the time.
Just because the gem is installed on your machine does not mean it is part of your bundle. bundle exec scopes the available gems to only what is included in your Gemfile and those gems dependencies. See if i18n for that version shows up when you run bundle show.

Could not find gem 'rails (= 4.2.5) x86-mingw32' when running rails server

I'm trying to learn Ruby on Rails.
Currently been trying out Rails framework. I've installed it. Create new project in MyBlog folder, but when I try to run:
rails server
I get back an error:
Could not find gem 'rails (= 4.2.5) x86-mingw32' in any of the gem sources listed in your Gemfile or available on this machine. Run `bundle install` to install missing gems.
I've installed bundle as suggested. Had few problems with installing it as well, but I've found a soultion on the internet.
Before bundle install I was getting another error saying that it could not find gem 'sqlite3'
Did someone had similar problem? Can you help me with solving it?
Update:
Content of my Gemfile is:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Errors when try to run 'bundle install':
Try to install the following packages to succeed bundle install
sudo apt-get install build-essential
sudo apt-get install libgmp3-dev
These packages are for Linux environment. Find the alternatives for other environments. Let me know if you got any error.
open file Gemfile.lock, find and delete "x64-mingw32" then run the command:-
$bundle install
Late answer but this happened to me just now.
What worked for me was figuring out I accidently installed an older Ruby version.
In your last screenshot you received a line:
Make sure that `gem install json -v '1.8.3'` succeeds before bundling
This command probably failed due to an older Ruby version, get the latest version here (Assuming you're a windows user) https://rubyinstaller.org/downloads/
P.S
Make sure you remove any previous Ruby / Rails installations.
What you need is a "With DEVKIT" installer, preferably the one they recommend on (starts with "=>").

Ruby "bundle install" error on Openshift

I'am fairly new in Ruby and terms of deploying app through remote tools. I've tried to deploy my App on free openshift account. And I connot run application.
When I run application i get this error:
You have already activated rack 1.5.2, but your Gemfile requires rack 1.6.0.
Using bundle exec may solve this. (Gem::LoadError)
So I try to run bundle exec but i got another error:
Gemfile syntax error:
/var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/Gemfile:24:
syntax error, unexpected ':', expecting $end
gem 'sdoc', '~> 0.4.0', group: :doc
I think it might be because I used Ruby 2.1.5 on local and Open shift runs Ruby 2.0 by default.
I had foud this topic How can I force a bundle install on OpenShift Online when my RAILS_ENV is set to development?
but i don't know if I am doing it right. I don't even know where to put this pre_build file. I tried to put it under /var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/.openshift/action_hooks/ . But I'm not sure if runtime is right repo.
EDIT 1:
This it my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
group: :doc do
gem 'sdoc', '~> 0.4.0'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]
SOLUTION:
As #Rajarshi Das said I had to change
gem 'sdoc', '~> 0.4.0', group: :doc
into
group: :doc do
gem 'sdoc', '~> 0.4.0'
end
I don know exactly why. Maybe some syntax issues as I was using Ruby 2.1.5 on local, and had to use 2.0.0 on production. And after that I had to run gem install rails even though I used rails quick start. Finally I had to manually add to Gemfile gem 'nokogiri'. Finally I could run bundle install and application started to work.
You can simply solve the error by following way
group :doc do
gem 'sdoc', '~> 0.4.0'
end
For platforms
platforms :jruby, :mingw, :mswin do
gem 'tzinfo-data'
end
Remove Gemfile.lock as You have already activated rack 1.5.2, but your Gemfile requires rack 1.6.0
Then check bundle install
I ssh to $app_root directory
gem install rack
it worked
Make sure your branch is being used for deployment
rhc app-configure --deployment-branch [BRANCH]
Then in your development environment update gems
# bundle install
It will change Gemfile.lock
$ git add -A
$ git commit -am "Updating gemfile"
$ git push
Wait until deployment is updated
I tried most of the solutions here, but I still got stuck. What the problem was is to install bundle for the current version of ruby being used. You will want to do a gem install bundler in app-root/runtime/repo.
Then RAILS_ENV=production bundle exec rails console
You can refer to this answer

Error trying to get rails server running in windows command prompt

I've been developing a (very simple) Rails project and have moved the files to a new machine. I have Ruby (version 2.0.0p195) and Rails (4.0.0) installed.
From the C:\Sites directory in command prompt (console), when I type 'rails server' I get a whole bunch of information that starts with:
Usage:
rails new APP_PATH [options]
...
...and continues with Options:, Runtime options:, Rails options: and so on.
When I cd to the directory of my copied project:
C:\Sites\elearning
and try 'rails server' I get the following error:
'mri_21' is not a valid platform. The available options are: [:ruby, :ruby_18, :ruby_19, :ruby_20, :mri, :mri_18, :mri_19, :mri_20, :rbx, :jruby, :mswim, :mingw, :mingw_18, :mingw_19, :mingw_20]
Does anyone know what I'm doing wrong? Is it possible to copy a rails project from another computer? And if so, how would I do that?
Any help, much appreciated.
Edit:
FYI, my gemfile is as follows:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.1.5'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'bootstrap-sass'
gem 'devise'
gem 'sqlite3'
gem 'thin'
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_21]
gem 'quiet_assets'
gem 'rails_layout'
gem 'byebug'
end
For those trying to transfer a mac project to PC: I've finally got rails server running.
First, in the gem file, I changed the reference 'mri_21' to 'mri_20' and changed the ruby version number to match my version of ruby.
I had other errors, but the short story is that I created a new rails project, copied MOST of the old project files into the corresponding files of the new project and EVENTUALLY noticed the comment at the bottom of the new (freshly created) routes.rb file:
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
So I added:
gem 'tzinfo-data', platforms: [:mingw, :mswin]
and all is, for now, right with the world.
So, if you're transferring a mac project to PC, you'll need to add the tzinfo-data gem to your gemfile.
Try running "gem update bundler" and see if that works.

Rails: Could not find gem 'sdoc (>=0) ruby'

I am developing a rails application in Mac after switching over from Windows. I thought that I had installed everything correctly. The IDE I'm using is Rubymine.
I receive numerous error messages when the rake command is run at the start of a new application. The cause is:
/Users/johncase/.gem/ruby/2.0.0/gems/bundler-1.5.1/lib/bundler/resolver.rb:302:in `resolve': Could not find gem 'sdoc (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)
I have installed sdoc multiple times through different methods, but I keep receiving the error. I have researched this problem and found many answers that have not worked.
I've tried: 'http://rubygems.org' instead of 'https://rubygems.org' then a bundle install with no success.
I've tried deleting the Gemfile.lock then bundle installing with no success.
Perhaps the answer is obvious, but I cannot seem to find it. Any assistance with this problem would be much appreciated.
Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'mysql2'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
This is because the gem is installed, but not being required. You either need to remove the require: false in the Gemfile or require it manually in your rake task. There is a lengthy explanation of this here: Bundler: What does :require => false in a Gemfile mean?

Resources