Undefined method 'secret_key' in Stripe API integration - ruby-on-rails

I am working on integrating Stripe with my Rails app. Per Stripe's documentation, I've added the following to 'config/initializers/stripe.rb', and set the environmental variables to the test keys:
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
(Editing to add that as suggested, I changed this to the following)
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'] ||= Rails.application.secrets.stripe_publishable_key,
:secret_key => ENV['STRIPE_SECRET_KEY'] ||= Rails.application.secrets.stripe_secret_key,
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
When I try to do anything now (generate a controller, say, or run the server), I get an error saying I have an "undefined method `secret_key'":
$ rails s
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/stripe-rails-0.3.1/lib/stripe/engine.rb:20:in `block in <class:Engine>': undefined method `secret_key' for #<Hash:0x000000066aa1e8> (NoMethodError)
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
from /home/ubuntu/workspace/junkyardstorefinal/config/environment.rb:5:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /home/ubuntu/workspace/junkyardstorefinal/config.ru:3:in `block in <main>'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /home/ubuntu/workspace/junkyardstorefinal/config.ru:in `new'
from /home/ubuntu/workspace/junkyardstorefinal/config.ru:in `<main>'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in `app'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in `start'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ubuntu/workspace/junkyardstorefinal/bin/rails:8:in `require'
from /home/ubuntu/workspace/junkyardstorefinal/bin/rails:8:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ubuntu/workspace/junkyardstorefinal/bin/spring:13:in `require'
from /home/ubuntu/workspace/junkyardstorefinal/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
What other data would be helpful to anyone who can help? That's the entirety of stripe.rb up there, and I can't find anywhere else that I've used "secret_key" or anywhere else that it appears in the tutorial I was originally working through. Nor have I touched any of the files mentioned in the full trace.
Oddly, although I can't start the server on Cloud9, when I use Heroku to look at it, the app launches and works just fine -- other than a problem connecting to Redis that prevents it from displaying the user's cart.
(Updating to add: now that I've merged the branch I was on and tried to push the merged master branch, which means Heroku compiles it now, I find that I also can't push to Heroku from the master branch without getting "NoMethodError: undefined method `secret_key' for #" and "push rejected".)

I think your error is the ENV['PUBLISHABLE_KEY'] and ENV['SECRET_KET'] is nil.
To solve your problem. In the terminal
$export PUBLISHABLE_KEY=yourpublisablekey
$export SECRET_KEY=yoursecretkey
$rails s
I would like to encourage you to put your key's in your secret.yml like
development:
stripe_publishable_key: yourpublisablekey
stripe_secret_key: yoursecretkey
production:
stripe_publishable_key: yourpublisablekey
stripe_secret_key: yoursecretkey
You can access this by simple adding Rails.application.secrets.stripe_publishable_key and Rails.application.secrets.stripe_secret_key
For example in your config/initializers/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'] ||= Rails.application.secrets.stripe_publishable_key,
:secret_key => ENV['SECRET_KEY'] ||= Rails.application.secrets.stripe_secret_key
}
Hope it helps.

It turned out that the solution was to take out the last line of stripe.rb entirely. I commented it out at the suggestion of someone over at CodeNewbie, to make sure that it was actually setting my stripe configurations. Surprisingly, once I commented that line out (
'Stripe.api_key = Rails.configuration.stripe[:secret_key]'), everything started working perfectly.

Years later I came across a similar issue with stripe-rails, using Rails 5.2.1
The solution was to add the keys to credentials, as per current rails standard, and instead of using an initializer 'stripe.rb' I used the development.rb and production.rb files inside the envirnoments folder.
So, on my development.rb I have something like this:
Rails.configuration.stripe.secret_key = Rails.application.credentials.stripe[:dev_secret_key]
Rails.configuration.stripe.publishable_key = Rails.application.credentials.stripe[:dev_publishable_key]
And similar code for production.rb

Related

uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError) - [learn-ruby-on-rails] Tutorial

I'm following the book "Learn Ruby on Rails" by Daniel Kehoe. I can't seem to get past the end of Chapter 10, start of Chapter 11, where I start the application server following the changes within development.rb
Here is the output:
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/adrian/workspace/learn-rails/config/environments/development.rb:67:in `block in <top (required)>': uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/railtie.rb:210:in `instance_eval'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/railtie.rb:210:in `configure'
from /Users/adrian/workspace/learn-rails/config/environments/development.rb:1:in `<top (required)>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:598:in `block (2 levels) in <class:Engine>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:597:in `each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:597:in `block in <class:Engine>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `call'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
from /Users/adrian/workspace/learn-rails/config/environment.rb:5:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/config.ru:3:in `require_relative'
from /Users/adrian/workspace/learn-rails/config.ru:3:in `block in <main>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /Users/adrian/workspace/learn-rails/config.ru:in `new'
from /Users/adrian/workspace/learn-rails/config.ru:in `<main>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/bin/rails:9:in `require'
from /Users/adrian/workspace/learn-rails/bin/rails:9:in `<top (required)>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/bin/spring:13:in `require'
from /Users/adrian/workspace/learn-rails/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Now, I've done a lot of research prior to submitting this, others have had similar issues i.e. http://stackoverflow.com/questions/37796350/syntaxis-error-when-start-rails-server-after-first-configuration but those were related to ENV errors with the config/secrets.yml file.
I've also seen suggestions to delete the following line within development.rb:
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
but that doesn't seem to help, only giving me the following error message:
Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/adrian/workspace/learn-rails/config/initializers/new_framework_defaults.rb:15:in `<top (required)>': undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:651:in `load_config_initializer'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:615:in `each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `call'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /Users/adrian/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
from /Users/adrian/workspace/learn-rails/config/environment.rb:5:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/config.ru:3:in `require_relative'
from /Users/adrian/workspace/learn-rails/config.ru:3:in `block in <main>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /Users/adrian/workspace/learn-rails/config.ru:in `new'
from /Users/adrian/workspace/learn-rails/config.ru:in `<main>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/bin/rails:9:in `require'
from /Users/adrian/workspace/learn-rails/bin/rails:9:in `<top (required)>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
from /Users/adrian/.rvm/gems/ruby-2.3.1#learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/adrian/workspace/learn-rails/bin/spring:13:in `require'
from /Users/adrian/workspace/learn-rails/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Here is the content of my development.rb file:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 587,
domain: Rails.application.secrets.domain_name,
authentication: "plain",
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
# Send email in development mode?
config.action_mailer.perform_deliveries = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
Pretty bummed out about this, I was following the tutorial and really getting into it. I'm really stumped as to what I've done to create this error...
Any help would be appreciated!
EDIT: I ultimately deleted and started the tutorial again. This time I specified the exact rails version I wanted to install (to follow the tutorial) rather than install the latest.
tl;dr: Re-create your Rails project, providing the specific Rails version.
Often this occurs because you have a newer version of Rails installed than the one called for in your .railsrc or template.rb.
If this is the case, when you run rails new my_new_app, the newest version is used by default for the earlier steps of the process, but then once the template/railsrc version is installed, latter steps use this version. This causes compatibility issues.
You can verify that this is your problem by comparing the output of rails -v (in the directory where you called rails new) with what's in your .railsrc or template.rb. If they are different, there is an easy fix:
Recreate your Rails app, specifying the same Rails version from your .railsrc or template.rb in the command line call:
rails _4.2.5.1_ new my_new_app
You need to add the listen gem to your Gemfile (preferably within the development group) and run bundle install.

Run code on the start of a rails server

When the Ruby on Rails application starts I want it to run a block of code so that the database is filled with the required data. I've been searching for hours for a solution, none of the given solutions that I found worked. The following is the solution that I implemented.
In application.rb I placed the following block of code:
def fill_db
redirect_to url_for(:controller => :item, :action => :init)
self.delay(:run_at => 10.minute.from_now).fill_db
end
config.after_initialize do
redirect_to url_for(:controller => :item, :action => :init)
fill_db
end
I tried to implement dozens of other variants of this but none of them worked.
The error I get is this:
C:\xampp\htdocs\dev-ruby\untitled1>rails s
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/railtie.rb:196:in `method_missing': undefined method `url_for' for Untitled1::Application:Class (NoMethodError)
from C:/xampp/htdocs/dev-ruby/untitled1/config/application.rb:40:in `block in <class:Application>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:36:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:in `each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
from C:/xampp/htdocs/dev-ruby/untitled1/config/environment.rb:5:in `<top (required)>'
from C:/xampp/htdocs/dev-ruby/untitled1/config.ru:3:in `require'
from C:/xampp/htdocs/dev-ruby/untitled1/config.ru:3:in `block in <main>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from C:/xampp/htdocs/dev-ruby/untitled1/config.ru:in `new'
from C:/xampp/htdocs/dev-ruby/untitled1/config.ru:in `<main>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in `app'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/server.rb:139:in `log_to_stdout'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/server.rb:78:in `start'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
The same code works in a controller, but then it's not executed at the start of the rails server.
You cannot use redirect_to inside application.rb. This is part of the ActionController classes. Here are two things that you can do instead
1) Implement db:seed - there is a db/seed.rb that you can use to populate initial database values. After you deploy the code just run bin/rails db:seed to run this task that will fill out the database
or
2) Add before_action to applicationController
class ApplicationController < ActionController::Base
before_action :fill_db
end
To prevent from executing this method add conditional like unless populated?
Hope it helps

Error shows up in server when using private_pub gem

I've been trying to use the private_pub gem for real-time updates in sample app so I can learn it and use it on the app I'm working on . But it always throws the following error when I type
rails s
shyam#shyam-SATELLITE-C50-B:~/Ajaxtry$ rails s
=> Booting Thin
=> Rails 4.2.2 application starting in development on
http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/private_pub-1.0.3/lib/private_pub.rb:21:in `load_config': uninitialized constant YAML (NameError)
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/private_pub-1.0.3/lib/private_pub/engine.rb:8:in `block in <class:Engine>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/initializable.rb:30:in `instance_exec'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/initializable.rb:30:in `run'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/initializable.rb:54:in `run_initializers'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/application.rb:352:in `initialize!'
from /home/shyam/Ajaxtry/config/environment.rb:5:in `<top (required)>'
from /home/shyam/Ajaxtry/config.ru:3:in `require'
from /home/shyam/Ajaxtry/config.ru:3:in `block in <main>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /home/shyam/Ajaxtry/config.ru:in `new'
from /home/shyam/Ajaxtry/config.ru:in `<main>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/server.rb:61:in `app'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/server.rb:78:in `start'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
from /home/shyam/Ajaxtry/bin/rails:9:in `require'
from /home/shyam/Ajaxtry/bin/rails:9:in `<top (required)>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/client/rails.rb:28:in `load'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/client/rails.rb:28:in `call'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/client/command.rb:7:in `call'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/client.rb:28:in `run'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/bin/spring:49:in `<top (required)>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/binstub.rb:11:in `load'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.5.0/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/shyam/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/shyam/Ajaxtry/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
The thin server seems to be working fine. Would appreciate any help .
I'm using ruby -v 2.2.2p95 and rails 4.2.2
UPDATE:
I do not think that it is with either the private_pub gem or the Sync gem(I tried using Sync just to make sure). Its still showing the same error. Since it says YAML is an uninitialized constant, i checked the function storing the YAML load and it looks like the following:
#.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/sync-0.3.5/lib/sync.rb
def load_config(filename, environment)
reset_config
yaml = YAML.load(ERB.new(File.read(filename)).result)[environment.to_s]
raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil?
yaml.each{|key, value| config[key.to_sym] = value }
setup_logger
if adapter
setup_client
else
setup_dummy_client
end
end
Why doesn't ruby recognize that YAML?
Private Pub does not work with Rails 4. It has been forked to this gem:
https://github.com/gregmolnar/chatter
See this thread and comment: https://github.com/ryanb/private_pub/issues/83#issuecomment-23869164

Rails s error: `method_missing': undefined method `active_record'

My rails project works before. I got this error because I deleted mysql and everything associated mysql.
Then I reinstalled mysql. It got this error. Then I reinstalled ruby and rails. The error is still here. Using "rails new myapp",
then "bundle instal",
then "rails s",
I got the following error:
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
**/home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_record' for #<Rails::Application::Configuration:0x0000000303cae8> (NoMethodError)
from /home/cwu/Dropbox/project/web/atop/config/environments/development.rb:23:in `block in <top (required)>'**
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:24:in `class_eval'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:24:in `configure'
from /home/cwu/Dropbox/project/web/atop/config/environments/development.rb:1:in `<top (required)>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:590:in `each'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:590:in `block in <class:Engine>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/cwu/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/cwu/Dropbox/project/web/atop/config/environment.rb:5:in `<top (required)>'
from /home/cwu/Dropbox/project/web/atop/config.ru:3:in `require'
from /home/cwu/Dropbox/project/web/atop/config.ru:3:in `block in <main>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /home/cwu/Dropbox/project/web/atop/config.ru:in `new'
from /home/cwu/Dropbox/project/web/atop/config.ru:in `<main>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from /home/cwu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
The error is clear that in config/environments/development.rb:23 you configure active_record which is not loaded.
Just remove
config.active_record.migration_error = :page_load
Will be ok.
Leedy Liu is right to some degree, but if you're getting this error when you create a new Rails app, t suggests a deeper problem with your environment
According to this answer, you may have require "active_record/railtie" commented out in your application.rb file. Please check to make sure this is not the case
You may have to re-install Rails with ActiveRecord to ensure the functionality is restored with your app. Have you tried this:
gem install bundler
gem install rails
bundle install
Other than that, you need to ensure Ruby on Rails is installed correctly. What env are you running? Linux or Windows?
As a general fix, remove all references to active_record. Easiest way is to do a find on the root directory of "active_records", find all usages, and remove them. I found usages in config/application.rb and config/environments/development and production.rb.
Try:
'gem install bundler'
then:
'bundle install'
again.
See if it clears up.
Comment config.active_record.raise_in_transactional_callbacks = true in config/application.rb and config.active_record.migration_error = :page_load in config/environments/development.rb.

Is it possible to 'unload' ActionMailer in Rails 3 application.rb?

I am trying to disable the parts of rails that i'm not using in my application, such as ActionMailer. Ib my application.rb, I made the following change
require "action_controller/railtie"
require "action_mailer/railtie"
#require 'rails/all'
And my app works fine. Now when I go and comment out the 'require "action_mailer/railtie"' line, I get the following error. I don't haveany mailers installed, so what's going on?
Thanks
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/railtie/configuration.rb:77:in `method_missing': undefined method `action_mailer' for #<Rails::Application::Configuration:0x00000002c337f8> (NoMethodError)
from /home/test/shipped/deluxe/deluxe/config/environments/development.rb:18:in `block in <top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:47:in `class_eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:47:in `configure'
from /home/test/shipped/deluxe/deluxe/config/environments/development.rb:1:in `<top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application/bootstrap.rb:11:in `block in <module:Bootstrap>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
from /home/test/shipped/deluxe/deluxe/config/environment.rb:6:in `<top (required)>'
from /home/test/shipped/deluxe/deluxe/config.ru:3:in `require'
from /home/test/shipped/deluxe/deluxe/config.ru:3:in `block in <main>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /home/test/shipped/deluxe/deluxe/config.ru:1:in `new'
from /home/test/shipped/deluxe/deluxe/config.ru:1:in `<main>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:162:in `app'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/server.rb:65:in `start'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Be careful, config.frameworks is deprecated in Rails 3!
The error you've got is coming from the #18 line of the file development.rb :
config.action_mailer.raise_delivery_errors = false
Since you do not require it anymore, config.action_mailer is undefined. You just have to comment the line and you will be fine.
In application.rb
config.frameworks -= [:action_mailer]

Resources