Rails / Memcached Error on Heroku - ruby-on-rails

I'm running into an issue using memcached with Rails 3.2.11 and Dalli 2.6.4 on Heroku. Memcached works great in development, but when I push to a staging environment on Heroku I'm running into the following error when I hit the cached page or when I write Rails.cache.clear in the console:
NoMethodError: undefined method `split' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/server.rb:35:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:334:in `new'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:334:in `block in ring'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:326:in `map'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:326:in `ring'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:238:in `flush'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/active_support/cache/dalli_store.rb:196:in `block in clear'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/active_support/cache/dalli_store.rb:291:in `block in instrument'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/notifications.rb:125:in `instrument'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/active_support/cache/dalli_store.rb:291:in `instrument'
from /app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/active_support/cache/dalli_store.rb:195:in `clear'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/cache/strategy/local_cache.rb:88:in `clear'
from (irb):1
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
The relevant parts of staging.rb:
config.cache_store = :dalli_store, nil,
{:namespace => 'STAGING', :expires_in => 1.day.to_i, :compress => true }
config.action_dispatch.rack_cache = nil
Any idea what might be causing this issue?

Still not sure what the problem was, but switching to using Dalli 1.1.5 fixed everything.

Related

Rails Console won't run (console error)

I'd like to run rails console command but it throw error everytime I run it.
Here is the error I get :
Loading development environment (Rails 5.1.4)
D:/RailsInstaller/Ruby2.3.3/lib/ruby/site_ruby/2.3.0/rbreadline.rb:6090:in `delete': invalid byte sequence in UTF-8 (ArgumentErr
or)
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/site_ruby/2.3.0/rbreadline.rb:6090:in `alloc_history_entry'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/site_ruby/2.3.0/rbreadline.rb:6123:in `add_history'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/site_ruby/2.3.0/readline.rb:368:in `<<'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:76:in `block (2 levels) in load_history'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:76:in `each'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:76:in `block in load_history'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:75:in `open'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:75:in `load_history'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:65:in `extended'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:21:in `extend'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:21:in `init_save_history'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:45:in `save_history='
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb/context.rb:91:in `initialize'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb.rb:426:in `new'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb.rb:426:in `initialize'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb.rb:383:in `new'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/irb.rb:383:in `start'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/console/console_command.rb:6
2:in `start'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/console/console_command.rb:1
7:in `start'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/console/console_command.rb:9
7:in `perform'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I've tried to reinstall/reinstall and clean every version of ruby with no success. I use Ruby 2.3.3 and rails 5.1.4.
Thanks
Since you are on Windows(I'm assuming since you have D:/):
Try installing rb-readline gem in your development group. That's the easiest way for solving readline issues.
There are other solutions as well if that doesn't work.

NameError: uninitialized constant CarrierWave::Storage::Fog

I have tried several solution given on stackoverflow and github, but couldnt find the solution. I am using carrierwave (0.10.0) and fog-aws (0.8.1) gems for my app to upload image to S3.
NameError: uninitialized constant CarrierWave::Storage::Fog
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `eval'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `eval'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `storage'
from /home/pulkit/dev/roid/rails/appbrowzer/app/uploaders/publisher_action_icon_uploader.rb:11:in `<class:PublisherActionIconUploader>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/uploaders/publisher_action_icon_uploader.rb:3:in `<top (required)>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/models/manage_channel_action.rb:3:in `<class:ManageChannelAction>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/models/manage_channel_action.rb:1:in `<top (required)>'
from (irb):1
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
And when i tried using the fog(1.37.0) gem instead of the fog-aws gem, then i am getting the different error.
ArgumentError: is not a recognized provider
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/fog-core-1.35.0/lib/fog/core/services_mixin.rb:12:in `new'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/fog-core-1.35.0/lib/fog/storage.rb:27:in `new'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:102:in `connection'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:356:in `connection'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:368:in `directory'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:261:in `store'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:80:in `store!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:59:in `block in store!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:58:in `store!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:375:in `store!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:207:in `store_icon!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:432:in `block in make_lambda'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:228:in `block in halting_and_conditional'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:506:in `block in call'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:506:in `each'
... 10 levels...
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:286:in `block in save'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:285:in `save'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/persistence.rb:34:in `create'
from (irb):1
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'2.3.0 :002 >
Update your gemfile from gem "fog-aws" to gem 'fog', require: 'fog/aws'.
Make sure your configure file(carrierwave.rb) is in initializers folder.
Fixed the issue by adding Fog gem in my Gemfile
gem 'fog', require: 'fog/aws'
Removed the configuration file from lib/carrierwave/storage/fog.rb as mentioned for fog-aws gem and placed the carrierwave configuration in config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'XYZ',
:aws_secret_access_key => 'ABC',
:region => 'region'
}
config.fog_directory = 'bucket_name'
end
Have you included the "fog-aws" gem? I feel like I had a similar error for not following this section of the documentation: https://github.com/carrierwaveuploader/carrierwave#using-amazon-s3
For me this was fixed by moving the config.storage = :fog after the config.fog_credentials = ... line in the Carrierwave initializer.
via #mshibuya

Undefined method 'secret_key' in Stripe API integration

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

rails acts-as-taggable-on throwing error in production mode

I am using rails 3.2.1 and ruby 1.9.3p448.
acts-as-taggable-on works fine in development mode but in production mode it throws an error below.
NoMethodError: undefined method `association_class' for nil:NilClass
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.2/lib/active_record/associations.rb:157:in `association'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.2/lib/active_record/associations/builder/association.rb:44:in `block in define_readers'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/acts-as-taggable-on-2.4.1/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:284:in `tags_on'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/acts-as-taggable-on-2.4.1/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:249:in `tag_list_cache_on'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/acts-as-taggable-on-2.4.1/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:254:in `tag_list_on'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/acts-as-taggable-on-2.4.1/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:44:in `tag_list'
from (irb):1
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /Users/navneet/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Heroku nil class error while saving an object

I have an application on heroku which uses mongoid and delayed_job and i have changed the ruby version from 1.9.2 to 1.9.3 I am getting an error
undefined method `match' for nil:NilClass
while I try to save an object to mongoid data base my mongoid.yaml file looks like
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
options:
skip_version_check: true
safe: true
the trace is here
NoMethodError: undefined method `match' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `new'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `parse'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:62:in `create_session'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:43:in `default'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:109:in `default'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:378:in `__session__'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:213:in `mongo_session'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:157:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:25:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations.rb:27:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations/insert.rb:27:in `block in persist'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels) in prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in `_run__4034630009416245289__create__685777988298500290__callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
... 2 levels...
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:24:in `block in prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in `_run__4034630009416245289__save__685777988298500290__callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/callbacks.rb:114:in `run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:23:in `prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence.rb:50:in `insert'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence.rb:79:in `save'
from (irb):2
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
any one can help me out? thanks in advance
The error is happening because the input parameter to this method https://github.com/mongoid/mongoid/blob/v3.0.13/lib/mongoid/sessions/mongo_uri.rb#L49 is nil.
Looking further back up the call stack to find out where this string comes from (see https://github.com/mongoid/mongoid/blob/v3.0.13/lib/mongoid/sessions/factory.rb#L103) it looks like your uri config param is nil. The uri key is present but empty, so can you check your MONGOHQ_URL configuration param by running heroku config. This should have been set by the MongoHQ addon.
The Ruby 1.9.1 paths in the stack trace are not anything to worry about. See Why Do Heroku Stack Traces indicate Ruby 1.9.1 is in use?

Resources