Understanding Gemfile (Rails): "require mongo" unnecessary if "gem 'mongo'" is already included? - ruby-on-rails

This is our Gemfile.
Is the line require mongo redundant since gem 'mongo' is already included?
If not, what is the purpose of require mongo?
We're on Rails 3.
Thanks!
source 'http://rubygems.org'
require 'rubygems'
require 'mongo'
gem 'rails', '3.0.6'
gem 'mongo'
gem 'mongo_mapper'
gem 'fastercsv'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
gem 'mysql'
gem 'whois'

You shouldn't put require statements in your Gemfile. This is also true for the require 'rubygems' on the line before.
What require does, is what it always does: load the gem. The Gemfile is loaded when you run bundle install. If you try to load a gem before bundle install has run, the gem might not be installed yet.
Gems specified in your Gemfile are required by Rails by default too, by the way.

Related

Unable to 'bundle install' RoR 3.0.1

Here is a link to my screen cap. http://imgur.com/bbLud (SO doesn't allow noobs to post pics)
The problem.
Trying to bundle install and it keeps throwing the 'this version requires a different version of bundler' error. So I uninstall the current version, check my versions of bundler and it still appears. I go to uninstall it again and it tell me it doesn't exist. Can someone please lend a thought.
EDIT: Contents of Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', '1.0.0', :require => 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => '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
Try to manually install bundler 1.0.0 using gem install bundler --version "1.0.0" and then run again bundle install.
UPDATE: Looking at the screenshot in the other answer it seems you already have bundler 1.0.0, BTW give it a try anyway. It seems the bundle command still points to the newer version, what do you get if you run bundle -v?
The error is at it says in the screenshot, you are using rails 3.0.1.
do uninstall without version
gem uninstall bundler
it will ask you which version you want to remove then remove it, select 1.3.1 to uninstall, do a bundle install again and if it still shows error post it back here.

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)

Creating a Gemfile with RVM

I have a rails 2.3.8 app. I just installed RVM, and apparently things are working ok (I created a very simple rails project to check that rails and mysql were running ok).
I am now trying to create a Gemfile... but am facing a problem with Thinking-Sphinx. Here is the current version of my Gemfile:
source :rubygems
source "http://rubygems.org"
source :rubyforge
source "http://gems.rubyforge.org"
source :gemcutter
source "http://gemcutter.org"
gem 'SystemTimer', :platforms => :ruby_18
gem "rails", "2.3.5"
# make sure to run "bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config" in terminal before running "bundle install" as per documentation in http://gembundler.com/man/bundle-config.1.html
gem "mysql"
gem "tlsmail"
gem 'delayed_job'
gem 'will_paginate', '~> 2.3.11'
gem "chronic"
gem "nokogiri"
gem "sphinx", '0.9.10.2122'
gem 'thinking-sphinx', '< 2.0.0', :require => 'thinking_sphinx'
gem 'ts-delayed-delta', :require => 'thinking_sphinx/deltas/delayed_delta'
gem "mini_magick"
gem "faker"
gem "populator"
gem "rspec"
gem "geokit"
gem "geokit-rails"
And my Rakefile is:
require 'thread'
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require 'thinking_sphinx/tasks'
require 'thinking_sphinx/deltas/delayed_delta/tasks'
begin
gem 'delayed_job', '~>2.0.3'
require 'delayed/tasks'
rescue LoadError
STDERR.puts "Run `rake gems:install` to install delayed_job"
end
When I run
rake ts:config
I get the following error message:
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
* bin_path
* searchd_binary_name
* indexer_binary_name
For more information, read the documentation:
http://freelancing-god.github.com/ts/en/advanced_config.html
Generating Configuration to /Users/alex/Sites/myproject/config/development.sphinx.conf
rake aborted!
uninitialized constant ThinkingSphinx::Deltas::DelayedDelta
Tasks: TOP => ts:config => thinking_sphinx:configure
(See full trace by running task with --trace)
I've been trying different things for a couple hours but can't find how to solve the problem... would love some help!
Try bundle exec rake ts:config
This will use the version you specified in your Gemfile.
My advice is to not use RVM. It is a good idea, but poorly implemented. If you need multiple ruby versions like me it is far less of a hassle to just create aliases for each one.
RVM causes issues from time to time, using aliases never does.

Rake 0.9.1 causing rake:db:migrate to yield deprecation issue, can't downgrade to 0.8.7

I ran a bundle install on my Gemfile recently, and tried to rake:db:migrate. This migration didn't work, and outputs:
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method SampleApp::Application#task called at /Users/joshuaballoch/.rvm/gems/ruby-1.9.2-p180#rails3tutorial3/gems/railties-3.0.3/lib/rails/application.rb:214:in `initialize_tasks'
I read on another post that I should uninstall 0.9.1, but for some reason some gem I have requires 0.9.1 after the uninstall, so I don't know how to fix this. Any suggestions?
FYI my gemfile is:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'
group :development do
gem 'rspec-rails', '2.3.0'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.3.1'
end
group :test do
gem 'rspec', '2.3.0'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
end
Have you tried running it like so: bundle exec rake db:migrate
the bundle exec command runs your request in the environment defined by the bundle, so if your global gems differ this may help.
If not, you can add gem "rake", "0.8.7" to your gemfile, bundle install then try again. Your other dependency should still be met as you aren't removing 0.9.1, just asking bundle exec to use a different version.
Rails 3.0.8 was released yesterday, and includes "Fixing Rake 0.9.x integration". Worth a try.

Resources