Rails app with mongoid ... (Mongoid::Errors::NoSessionConfig): No configuration could be found for a session named 'default' - mongodb

With reference to https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927
I've done all the necessary changes ... still the issue is there ...
spec_helper.rb file
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", FILE)
require 'rspec/rails'
require 'rspec/autorun'
require 'rails/mongoid'
Gemfile
gem 'rails', '4.0.0'
gem 'rspec-rails', '~>2.14.0'
gem 'mongoid', git: 'https://github.com/mongoid/mongoid.git'
gem 'bson_ext'
mongoid.yml
development:
sessions:
default:
database: mongo_demo_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: mongo_demo_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
Following is the Error Log which is generated when I run my rails server with $rails s ...
/home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions/factory.rb:27:in create': (Mongoid::Errors::NoSessionConfig)
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:137:inwith_name'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:390:in __session__'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:227:inmongo_session'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:171:in collection'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual/mongo.rb:265:ininitialize'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:51:in new'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:51:increate_context'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:34:in context'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:18:inlast'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/findable.rb:130:in last'
from /home/nikunj/Practice/mongo_demo/app/rules/myrule_book.rb:5:inclass:Myrule_Book'
from /home/nikunj/Practice/mongo_demo/app/rules/myrule_book.rb:3:in <top (required)>'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:inload'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in block in load_file'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:615:innew_constants_in'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:422:in load_file'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:323:inrequire_or_load'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:462:in load_missing_constant'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:inconst_missing'
from /home/nikunj/Practice/mongo_demo/config/environments/development.rb:30:in block in <top (required)>'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:24:inclass_eval'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:24:in configure'
from /home/nikunj/Practice/mongo_demo/config/environments/development.rb:1:in'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in require'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inblock in require'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in load_dependency'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inrequire'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:591:in block (2 levels) in <class:Engine>'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:590:ineach'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:590:in block in <class:Engine>'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:30:ininstance_exec'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:30:in run'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:55:inblock in run_initializers'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:150:in block in tsort_each'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:183:inblock (2 levels) in each_strongly_connected_component'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:210:in block (2 levels) in each_strongly_connected_component_from'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:219:ineach_strongly_connected_component_from'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:209:in block in each_strongly_connected_component_from'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:44:ineach'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:44:in tsort_each_child'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:203:ineach_strongly_connected_component_from'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:182:in block in each_strongly_connected_component'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:180:ineach'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:180:in each_strongly_connected_component'
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:148:intsort_each'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:54:in run_initializers'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/application.rb:215:ininitialize!'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in method_missing'
from /home/nikunj/Practice/mongo_demo/config/environment.rb:5:in'
from /home/nikunj/Practice/mongo_demo/config.ru:3:in require'
from /home/nikunj/Practice/mongo_demo/config.ru:3:inblock in '
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/builder.rb:55:in instance_eval'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/builder.rb:55:ininitialize'
from /home/nikunj/Practice/mongo_demo/config.ru:in new'
from /home/nikunj/Practice/mongo_demo/config.ru:in'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/builder.rb:49:in eval'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/builder.rb:49:innew_from_string'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/builder.rb:40:in parse_file'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/server.rb:277:inbuild_app_and_options_from_config'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/server.rb:199:in app'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands/server.rb:48:inapp'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385#global/gems/rack-1.5.2/lib/rack/server.rb:314:in wrapped_app'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands/server.rb:75:instart'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:78:in block in <top (required)>'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:73:intap'
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:73:in <top (required)>'
from bin/rails:4:inrequire'
from bin/rails:4:in `'

Your mongoid.yml has an error "hosts:" key should be inside of "default:" because it is a required configuration for sessions
Please check http://mongoid.org/en/mongoid/docs/installation.html#configuration

I had the same issue and error message - In my case it was caused because the yml config file wasn't loaded. I added the following line
Mongoid.load!('config/mongoid.yml')
to config/application.rb and it solved the problem

may be The problem is in the gem file, you did't mention the version of mongoid gem. in gem file change gem "mongoid" to gem "mongoid" , '~> 4.0.2' and run bundle install restart server and console.

Related

Could not parse for environment production: no 'environments'

I have already installed puppet-server 3.7.5 and foreman. But when I am running this command I am getting below error.
~]# foreman-installer --foreman-db-type mysql
Error:
/usr/lib/ruby/site_ruby/1.8/puppet/context.rb:54:in `lookup': Could not parse for environment production: no 'environments' in {:root_environment=>#<Puppet::Node::Environment:0x7fe3646d9620 #modulepath=[], #watching=true, #config_version=nil, #manifest=:no_manifest, #name=:"*root*">, :current_environment=>#<Puppet::Node::Environment:0x7fe3646d9620 #modulepath=[], #watching=true, #config_version=nil, #manifest=:no_manifest, #name=:"*root*">} at top of [[0, nil, nil]] (Puppet::Error)
from /usr/lib/ruby/site_ruby/1.8/puppet.rb:236:in `lookup'
from /usr/lib/ruby/site_ruby/1.8/puppet.rb:264:in `future_parser?'
from /usr/lib/ruby/site_ruby/1.8/puppet/parser/parser_factory.rb:12:in `parser'
from /usr/lib/ruby/site_ruby/1.8/puppet/node/environment.rb:541:in `perform_initial_import'
from /usr/lib/ruby/site_ruby/1.8/puppet/node/environment.rb:276:in `known_resource_types'
from /usr/lib/ruby/site_ruby/1.8/puppet/resource/type_collection_helper.rb:5:in `known_resource_types'
from /usr/lib/ruby/site_ruby/1.8/puppet/parser/parser_support.rb:120:in `import'
from /usr/lib/ruby/gems/1.8/gems/kafo_parsers-0.0.3/lib/kafo_parsers/puppet_module_parser.rb:38:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/kafo_parsers-0.0.3/lib/kafo_parsers/puppet_module_parser.rb:16:in `new'
from /usr/lib/ruby/gems/1.8/gems/kafo_parsers-0.0.3/lib/kafo_parsers/puppet_module_parser.rb:16:in `parse'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/puppet_module.rb:44:in `parse'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/configuration.rb:84:in `modules'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/configuration.rb:84:in `map'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/configuration.rb:84:in `modules'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/kafo_configure.rb:170:in `modules'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/kafo_configure.rb:152:in `params'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/kafo_configure.rb:185:in `set_parameters'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/kafo_configure.rb:66:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:126:in `new'
from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:126:in `run'
from /usr/lib/ruby/gems/1.8/gems/kafo-0.6.5/lib/kafo/kafo_configure.rb:116:in `run'
from /usr/sbin/foreman-installer:58
Looks like this is a bug introduced due to some changes in the way environments work in Puppet 3.7 and is not compatible with previous version. Based on bug filed here you will need to supply arguments to foreman installer.

rails-api not allowing any generation

I'm struggling trying to get the configuration of rails-api with the mongo_mapper gem.
I'm using rails v 4.1.1
gemfile looks as follows
source 'https://rubygems.org'
gem 'mongo'
gem 'mongo_mapper', :git => "git://github.com/mongomapper/mongomapper.git", :tag => "v0.13.0.beta2"
gem 'bson_ext'
gem 'railties'
I ran rails-api new test-app --skip-active-record which generates a simple file structure.
.
├── Gemfile
├── Gemfile.lock
├── README.rdoc
├── Rakefile
└── config.ru
After that, per the instructions on the README for mongo_mapper I specified the correct version in my gemfile so that it's compatible with Rails 4.
gem 'mongo_mapper', :git => "git://github.com/mongomapper/mongomapper.git", :tag => "v0.13.0.beta2"
According to
- http://mongomapper.com/documentation/getting-started/rails.html
- How can I get mongo mapper to generate the config/mongo.yml file in Rails 4
I should then be able to run bundle exec rails generate mongo_mapper:config. It was here I started running into issues.
I first realized I need railsties gem since it wasn't even letting me run rails generate.
$ bundle exec rails generate mongo_mapper:config
/Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/rubygems_integration.rb:248:in `block in replace_gem': railties is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/colinhhart/.rbenv/versions/2.1.0/bin/rails:22:in `<main>'
After adding that gem it allowed me to run bundle exec rails generate mongo_mapper:config but doesn't actually have access to that mongo generator. The output from the command is the standard rails help info including usage, options etc.
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/colinhhart/.rbenv/versions/2.1.0/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
What I've tried so far
I've tried building out what the generator is supposed to build as is described in this guide
http://technicaldebt.com/getting-started-with-ruby/mongomapper-ith-rails-quickstart/
But then realized that even if I build that out there's obviously still some "glue" that I'm missing, which ties everything together. I built it out just in case and of course it still didn't work.
I've made sure to bundle and and reload the terminal appropriately.
Like I said, I'm pretty sure there's something necessary that gets skipped when I build the rails-api without active record.
Any thoughts on this? Would greatly appreciate the help.
For what it's worth this is the full output when I ran rails-api new my_app --skip-active-record.
$ rails-api new pitfworld_wide_atrocities_db --skip-active-record
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
(erb):19:in `template': undefined method `name' for []:Array (NoMethodError)
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `eval'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `result'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:116:in `block in template'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `call'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `render'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `block (2 levels) in invoke!'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `open'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `block in invoke!'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/empty_directory.rb:116:in `call'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/empty_directory.rb:116:in `invoke_with_conflict_check'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:60:in `invoke!'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions.rb:94:in `action'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:25:in `create_file'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:115:in `template'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/generators/rails/app/app_generator.rb:17:in `template'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/generators/rails/app/app_generator.rb:45:in `gemfile'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/generators/app_base.rb:133:in `build'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/generators/rails/app/app_generator.rb:176:in `create_root_files'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/application.rb:17:in `<top (required)>'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/cli.rb:14:in `<top (required)>'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/colinhhart/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rails-api-0.2.1/bin/rails-api:4:in `<top (required)>'
from /Users/colinhhart/.rbenv/versions/2.1.0/bin/rails-api:23:in `load'
from /Users/colinhhart/.rbenv/versions/2.1.0/bin/rails-api:23:in `<main>'
Solution
I came across that rails-api issue right as I was writing this post and it turned out that that was the issue, after banging my head forever thinking it was a mongo issue.
The issue has been fixed and closed but hasn't yet been released and will probably be released in rails-api v0.2.2.
Ultimately, I decided to just go into the rails-api source code and apply the changes locally.

Rails migration error with thumbs_up gem

I am using the thumbs_up gem to create a voting system. I am using PostgreSQL. When I run:
rails generate thumbs_up
I get the following error:
/usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:21:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/railties-4.0.4/lib/rails/generators/migration.rb:65:in `migration_template'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:22:in `create_migration'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/railties-4.0.4/lib/rails/generators.rb:156:in `invoke'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/railties-4.0.4/lib/rails/commands/generate.rb:11:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247#firehose/gems/railties-4.0.4/lib/rails/commands.rb:48:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
How do I fix this?
This is a bug in thumbs_up.
Check this issue on github: https://github.com/bouchard/thumbs_up/issues/96
I stumbled across the same error and fixed it with the help of the link above.
Apparently all you have to do is change a file in the thumbs_up gem (you will find the location of that gem in the error itself).
In file
[path to gem]/lib/generators/thumbs_up/thumbs_up_generator.rb
replace
def create_migration
migration_template 'migration.rb', File.join('db', 'migrate', 'thumbs_up_migration.rb')
end
with
def create_thumbs_up_migration
migration_template 'migration.rb', File.join('db', 'migrate', 'thumbs_up_migration.rb')
end
in your Gemfile require the gem this way:
gem 'thumbs_up', git: 'https://github.com/bouchard/thumbs_up.git', ref: 'f499a7c803c0a9fdcefe4275f2f0a10ca7964508'
then run
rails generate thumbs_up
This should work. Worked for me - hope this helps....

'Don't know how to build task' error in Capistrano 3

I'm trying to learn to use Capistrano 3 by following the DOCS and I've written a simple task to test my understanding.
The task is created in the default task dir in lib/capistrano/tasks:
desc "Check status of web server"
task :nginx_status do
on roles(:web) do |host|
execute 'service nginx status'
end
end
My config/deploy/staging.rb file contains the following:
set :stage, :staging
role :web, "192.168.0.11"
role :app, "192.168.0.11"
role :db, "192.168.0.11", primary:true
server '192.168.0.11', user: 'vagrant', roles: %w{web app}
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
My deploy.rb contains an app name and a repo url to github.
When I run cap staging nginx_status I get the following error:
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'nginx_status'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/task_manager.rb:62:in `[]'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:149:in `invoke_task'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/H/.rbenv/versions/2.1.1/bin/cap:23:in `load'
/Users/H/.rbenv/versions/2.1.1/bin/cap:23:in `<main>'
I also noticed that if I ran cap -vT the task nginx_status is not in the list(?)
On a side note, are SSH keys a must to connect to remote servers?
UPDATE 1
I found that if I place my task in config/deploy.rb it works. So the question I now have is how do you run tasks from the task dir?
UPDATE 2
So as per the Capfile the tasks dir is looked at by the following:
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
So I changed the task extension to .rake and it worked. However the documentation says it should be .cap
"We'll dive into those more later, but add those lines to a file in ./lib/capistrano/tasks, call it something like access_check.cap"
Take a look at this commit.
They've switched from .cap to .rake 3 months ago.
The whole idea is to make capistrano3 fully rake-compatible. Just use .rake extension for you tasks.

Section 5.4 Rails Tutorial

I'm tearing my hair out. I'm doing the Rails Tutorial by Hartl, and everything has been working until section 5.4.
It seems to be that I generated a new controller, then generated the integration_test user_pages, then the whole thing went haywire. I can't for the life of me work out what I've done wrong or where to start. I even tried destroying both and the same error comes out. Please help!
My Code
Jordan-Poulton:Projects academy$ cd first_app/
Jordan-Poulton:first_app academy$ subl .
Jordan-Poulton:first_app academy$ rails generate controller Users new --no-test-framework
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
create app/controllers/users_controller.rb
route get "users/new"
invoke erb
create app/views/users
create app/views/users/new.html.erb
invoke helper
create app/helpers/users_helper.rb
invoke assets
invoke coffee
identical app/assets/javascripts/users.js.coffee
invoke scss
create app/assets/stylesheets/users.css.scss
Jordan-Poulton:first_app academy$ rails generate integration_test user_pages
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
invoke rspec
create spec/requests/user_pages_spec.rb
Jordan-Poulton:first_app academy$ rails s
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/bundler-1.2.4/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:185:in `default_controller_and_action': missing :action (ArgumentError)
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:78:in `normalize_options!'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:61:in `initialize'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1304:in `new'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1304:in `add_route'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1284:in `decomposed_match'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1270:in `block in match'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1270:in `each'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/mapper.rb:1270:in `match'
from /Users/academy/Projects/first_app/config/routes.rb:6:in `block in <top (required)>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:260:in `draw'
from /Users/academy/Projects/first_app/config/routes.rb:1:in `<top (required)>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/file_update_checker.rb:78:in `call'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/file_update_checker.rb:78:in `execute'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/academy/Projects/first_app/config/environment.rb:5:in `<top (required)>'
from /Users/academy/Projects/first_app/config.ru:3:in `require'
from /Users/academy/Projects/first_app/config.ru:3:in `block in <main>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/academy/Projects/first_app/config.ru:in `new'
from /Users/academy/Projects/first_app/config.ru:in `<main>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/commands/server.rb:46:in `app'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/commands/server.rb:70:in `start'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/commands.rb:50:in `tap'
from /Users/academy/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Please check your controller. Content should be this
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def new
end
end
and your routes.rb
#config/routes.rb
FirstApp::Application.routes.draw do
get "users/new"
root to: 'pages#home'
Run the following commands before rails s, just in case:
bundle install
bundle update
rake db:migrate
Sometimes a rake db:reset could help, but this will destroy and rebuild your database in your development environment.