0

I am trying to integrate twitter/bootstrap in my very first rails app (followed this article http://www.opinionatedprogrammer.com/2011/11/twitter-bootstrap-on-rails/) and now I get this error which I am unable to understand/resolve.


    new-host:Talker Talker$ rails s
=> Booting Thin
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Projects/Talker/config/environment.rb:4:in <top (required)>': undefined methodInitialize' for Rails:Module (NoMethodError)
    from /Projects/Talker/config.ru:4:in require'
    from /Projects/Talker/config.ru:4:inblock in '
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
    from /Projects/Talker/config.ru:1:in new'
    from /Projects/Talker/config.ru:1:in'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:200:in app'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:46:inapp'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in start'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:55:inblock in '
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in tap'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in'
    from script/rails:6:in require'
    from script/rails:6:in'
This is how my environments.rb looks like

require File.expand_path('../application', FILE)
Rails.Initialize.run do |config|
config.gem 'mongo'
config.gem "mongo_mapper"
end
Talker::Application.initialize!

I am very new to rails so any help/direction is highly appreciated!

2 Answers 2

1

When following naren's instructions, have you removed the Rails.Initialize.run block from the environment.rb file? I know this probably may sound silly :)

Also, from the second error, I gather that you might be using Mongo HQ and if it is hosted on Heroku, they have a pretty detailed instruction manual on configuring your DB. Heroku MongoHQ Dev Center. Two things to check in your app:

  1. Is the MongoDB url (Mongo HQ's url) is configured properly? This is because, the second error says that there may be a problem with the link itself.

  2. Newer version of rails (3 and above) do not allow the config.gem syntax in the environment block. Rather, you need to add a initializer file in config/initializers. More on this on the MongoDB Documentation for Rails 3 section.

Hope this helps.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks I am going through MongoHQ docs... do you know what this line does? Rails.env => { 'uri' => ENV['MONGOHQ_URL'] || 'mongodb://localhost/sushi' } }
The MongoMapper.connect method converts a uri that is passed to it into host, port, database, username and password. More on this in the source code of MongoMapper (Scroll down to the connect method and you'll see a conversion of the Rails.env[:uri] into the 4 variables listed above.
Simply put, that statement adds a hash {'uri' => ENV['MONGOHQURL'] || 'mongodb://localhost/sushi'} into the Rails environment hash which is used by MongoMapper internally to connect to the Mongo database running at the specified location. The MongoHQ url is your MongoHQ account's URL. mongodb://localhost/sushi part, I don't know and I'm not sure — I'm assuming this is a url for the local installation on your machine, although, I would be using the simpler http://localhost:27017 version rather than that.
when i change it to localhost:27017, I get /Users/Talker/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/uri/common.rb:156:in `split': bad URI(is not URI?): (URI::InvalidURIError)
Is the ENV['MONGOHQ_URL'] variable set? Did some searching on this and came across this link: Same issue
|
1

I think you do not need to specify config.gem in Rails.Initialize. In your Gemfile under project root directory specify the gems. You can remove the above

gem "mongo"
gem "mongo_mapper"

Then install gems using bundle install. Now you should be having the gems

Please try restarting after removing the Rails.Initialize block

2 Comments

Thanks... but wen I do tht, I get this Exiting /.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/uri/common.rb:156:in split': bad URI(is not URI?): (URI::InvalidURIError) from /.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/uri/common.rb:174:in parse' from /.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/uri/common.rb:628:in parse' from /Projects/Talker/config/initializers/mogohq.rb:9:in get_connection' from /Projects/Talker/config/initializers/mogohq.rb:16:in `<top (required)>'
I have not used twitter bootstrap so not sure if you really require mongo and mongo_mapper gems. From the error I could figure out the the ruby version you are using and mongo gem are not compatible. If you do not require mongo gems comment them out in the gemfile. If you do need them you need to use the compatible mongo gems with ruby version you are using. I would trying creating a new rvm gemset( rvm gemset create talker ) and use the gemset to install gems in the new gemset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.