Why Bundler.require is not working the way it should - ruby-on-rails

I have an application where I segregated all my gem based on groups
source 'http://rubygems.org'
...
...
...
group :development, :test do
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'web-app-theme', '>= 0.6.2'
gem 'faker'
gem 'mailcatcher'
gem "pry"
gem 'annotate'
gem "unicorn"
gem "capistrano"
end
The important Thing over here is ruby-debug19
now in my config/application.rb
I have defined
Bundler.require *Rails.groups(:assets => %w(development test))
Still when I start my server
rails server --debugger
it give me this below error
`require': no such file to load -- ruby-debug (LoadError)
I have remove the ruby-debug19 from development group and put it in default it the server works
I compared the both the Gemfile.lock in either case
cat Gemfile.lock > intial_lock (When ruby-debug19 is in development group)
ran
bundle list
cat Gemfile.lock > final_lock (When ruby-debug19 is in default group)
also did a
diff initial_lock final_lock
No difference indicating the file are same
I also tried with
Bundler.require(:default, :assets, Rails.env)
Still no success
Can anyone let me know why Bundler.require is not working the way it should have

Check if you have not fall into the .bundle directory trap in your application directory It happen when you any time run anytime bundle install with --without options
Straight from bundle Gemfile manual
After running bundle install --without test, bundler will remember
that you excluded the test group in the last installation. The next
time you run bundle install, without any --without option, bundler
will recall it.
just remove .bundle/config directory from your application directory please first check the content first before removing it
Hope this help

Related

Rails - how do gems relate to doing 'bundle'

I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194

Why won't my Rails server run on OS X Lion?

I'm a beginner programmer and I'm trying to run the Rails Server through my command line. I type in "rails server" in my command line, and receive this error:
Could not find gem 'sqlite3-ruby (= 1.2.5, runtime)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
After receiving this error, I run 'bundle install'. Once I run 'bundle install', I type in "rails server" in my command line and receive the same error:
Could not find gem 'sqlite3-ruby (= 1.2.5, runtime)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
Here's a copy of my GemFile:
source 'http://rubygems.org'
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
Can someone help me get my rails server up and running? Thanks!
try deleting the "1.2.5" in your gemfile so the line looks like:
gem 'sqlite3-ruby', :require => 'sqlite3'
then run
bundle install
again
I think I once got this error a long time ago - it had something to do with having sqlite.dll in my bin or lib folder in my computer's ruby dir or something like that. I think Michael Hartl's tutorial mentions something about it.
Have you tried just
gem 'sqlite3'
You might also want to confirm that your gem is properly installed in your environment:
gem list
You can also get more information about a specific gem:
gem specification sqlite3-ruby
I am assuming that you have no issues with installing other gems - that is, you don't need to set up a http_proxy environment variable for bundle install.

Return Rails app to development mode with bundler

I've deployed my app to a remote machine using Capistrano and Passenger. The project is on GitHub, and I want to work on some bug fixes on my local machine. I've synced up everything, and branched to a new 'dev' branch on my local machine. When I try the simple rails server command I had been using while developing, I get errors relating to the gems bundled in my Gemfile, e.g. `require': no such file to load -- nokogiri/nokogiri (LoadError). But when I run bundle show nokogiri, it's present at /vendor/cache/ruby/1.9.1/gems/nokogiri-1.5.0.
Maybe this is just the wrong workflow entirely, but how do I get to a development mode on my local machine, so I can test changes before pushing them to the deployed app?
My Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.10'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'nested_scaffold'
gem 'rest-client'
gem 'pony'
gem 'mail'
gem 'logger'
gem 'json'
gem 'gmail'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
I suggest you delete .bundle directory (consider backing up whatever's inside .bundle/config first) and run your bundle install command again. You can do cat .bundle/config to echo its contents to your terminal (STDOUT).
Make sure you have chosen the correct gemset by doing rvm gemdir and gem list to see all the gems in the current gemset.
Start your server with rails s -e development (s is short for server)

bundler incorrectly trying to install "development" and "test" group gems in production

I have a small web app, which uses a bunch of gems. Some of them are only used for test and development environments. Now, when I try to start unicorn on the production server using the following command, it fails.
unicorn_rails -E production -D -c config/unicorn.rb
The error I see in the log files is:
Refreshing Gem list
Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.
I've pasted my gemfile below:
source 'http://rubygems.org'
gem 'rails', '3.0.1'
gem 'unicorn'
gem 'mongoid', '>= 2.0.0.beta.19'
gem 'devise'
gem 'cancan'
gem 'haml', '>= 3.0.0'
gem 'bson'
gem 'bson_ext'
gem 'formtastic'
gem 'bluecloth'
group :production do
gem 'capistrano'
end
group :development do
gem 'haml-rails'
gem 'hpricot', '0.8.2'
gem 'ruby_parser', '2.0.5'
gem 'less'
gem 'rspec-rails', '>= 2.0.1'
end
group :development,:test do
gem 'spork', '>=0.9.0.rc2'
gem 'mongoid-rspec'
end
group :test do
gem 'factory_girl_rails'
gem 'autotest'
gem 'cucumber-rails'
gem 'cucumber'
gem 'capybara'
gem 'shoulda'
gem 'database_cleaner'
gem 'test_notifier'
gem 'rspec', '2.0.1'
gem 'launchy'
end
Bundler is supposed to detect the right environment and ignore the other gems, right? Right now, I am deleting all the lines which are not in the default group on the server to get this working, but that's an ugly hack.
After a lot of digging I found the fix for this issue. All I had to do was run bundle install --without development test before starting the server. This adds a .bundle/config file in the rails root with the line BUNDLE_WITHOUT: test:development . Now whenever you run bundle install or start the server it'll ignore those groups.
From the documentation
The Bundler CLI allows you to specify
a list of groups whose gems bundle
install should not install with the
--without option. To specify multiple groups to ignore, specify a list of
groups separated by spaces.
bundle install --without test bundle
install --without development test
After running bundle install --without
test, bundler will remember that you
excluded the test group in the last
installation. The next time you run
bundle install, without any --without
option, bundler will recall it.
Also, calling Bundler.setup with no
parameters, or calling require
"bundler/setup" will setup all groups
except for the ones you excluded via
--without (since they are obviously not available).
In my case it was installing gems from jenkins env. So i had to set my own bundle_without variable in capistrano.
Gemfile
group :test, :development, :jenkins do
gem 'test-unit', '1.2.3'
gem 'rspec-rails'
end
deploy.rb
set :bundle_without, [:development, :test, :jenkins]
You haven't defined a production group =)

Rails bundler doesn't install gems inside a group

I have several gems including ruby-debug in a bundler group called :development. When I run the bundle command, these gems are ignored and it only installs the gems that are not in any group. How can I make sure bundler doesn't ignore the gems in the :development group?
Edit: This is what my Gemfile looks like.
source 'http://rubygems.org'
gem 'rails', '3.0.1'
# Auth gems
gem "devise", "1.1.3"
gem "omniauth"
# Bundle Mongoid gems
gem "mongoid", "2.0.0.beta.19"
gem "bson_ext"
# Asset gems
gem 'jquery-rails'
gem "jammit"
# Controller gems
gem 'inherited_resources', '1.1.2'
# View gems
gem 'haml'
gem 'formtastic', '~> 1.1.0'
# Nokogiri
gem "mechanize"
gem "json"
group :development do
gem "ruby-debug"
gem 'compass'
gem 'compass-colors'
gem 'pickler'
gem 'haml-rails'
gem 'rails3-generators'
gem "hpricot"
gem "ruby_parser"
gem 'fog'
end
Within a term session, it remembers the without option. If you first ran
bundle install --without development
it remembers that you did this and will automatically repeat this for the next
bundle install #remembers and includes --without development
running something else, like bundle install --without nothing should clear the cache. Am I right?
update 20150214: This is fixed in bundler 2.0, according to issue referenced in comment by #Stan Bondi (https://github.com/bundler/bundler/issues/2862). Thanks Stan.
If you are using rails, there will be a file config written into a hidden dir called .bundle in your rails root directory:
.bundle/config
This file, in my case, held exactly the without settings.
So I just deleted the .bundle directory:
rm .bundle -r
After that:
bundle install worked again as expected.
Using: bundler (1.5.2)
I had the same issue and --with flag worked for me. You need to pass group name, which you want to include. Like that:
bundle install --with development
gem 'aws-s3'
gem 'paperclip'
group :test do
gem 'rspec'
gem 'waitr'
gem 'faker'
end
gem 'rest-client', :group => :development
gem 'cucuber-rails', :groups => [:development,:test] (cucuber-rails gems comes under both group)
bundle install --without development #(ignore development group gems)
bundle install #(still bundle remembers --without development so result is still ignore development groups it will not install all gems)
bundle install --without nothing #(just clearing cache, now all the gems to be loaded into the ruby loadpath)
More
In fact Rails loads the :development group automatically when in development environment. Check whether Rails.env in you App really returns "development".
More Information about groups in Bundler:
http://gembundler.com/groups.html
I had a similar problem - thin in staging ignored - and the solution was to put it out if staging into the 'global' space:
gem 'thin'
group :production do
gem 'puma'
end
I've faced the same issue with bundler 2.1.4 When I checked my .bundle/config it has
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "development:test:build"
Remove groups from there and add BUNDLE_WITH to your groups.
BUNDLE_WITH: "development"
I've removed the ~/.bundle/config. but there was a file in my project directory. .bundle/config. Local directory files have precedence over the main config files.
If you can't figure out the reason, then you can just create a file in your project directory .bundle/config. and add this content there
BUNDLE_WITH: "development:test:anyGroupYouWant"

Resources