NameError: uninitialized constant CarrierWave::Storage::Fog - ruby-on-rails

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

Related

Missing required arguments: aws_access_key_id, aws_secret_access_key in server

I keep getting this error whenever I am trying to start the server validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError) I can't seem to solve the issue! I am almost sure that the issue is caused Carrierwave and fog gems to use amazon s3. But I am not sure exactly in which folder the issue is!
Here's my initializer/carrierwave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV["S3_ACCESS_KEY"], # required
:aws_secret_access_key => ENV["S3_SECRET_KEY"] # required
}
config.fog_directory = ENV["S3_BUCKET"] # required
end
here's my log:
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:268:in `handle_settings'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:98:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/services_mixin.rb:16:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/storage.rb:27:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:123:in `eager_load_fog'
from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:136:in `fog_credentials='
from /home/ubuntu/workspace/config/initializers/carrierwave.rb:2:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:158:in `configure'
from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave.rb:14:in `configure'
from /home/ubuntu/workspace/config/initializers/carrierwave.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:651:in `load_config_initializer'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `call'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
from /home/ubuntu/workspace/config/environment.rb:5:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /home/ubuntu/workspace/config.ru:3:in `block in <main>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/builder.rb:55:in `initialize'
from /home/ubuntu/workspace/config.ru:in `new'
from /home/ubuntu/workspace/config.ru:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/builder.rb:49:in `eval'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/builder.rb:49:in `new_from_string'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/server.rb:208:in `app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.5/lib/rack/server.rb:336:in `wrapped_app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ubuntu/workspace/bin/rails:9:in `require'
from /home/ubuntu/workspace/bin/rails:9:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `call'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/bin/spring:49:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/ubuntu/workspace/bin/spring:13:in `require'
from /home/ubuntu/workspace/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
My Bug
I had a the exact same error: validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError).
Bucket Restrictions and Limitations - Amazon Simple Storage Service
https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
Suggestion
Now, I personally avoid the secrets.yml approach. I suggest using fog for production and file storage for development. For example:
photo_uploader.rb
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_fill: [100, 100]
# Choose what kind of storage to use for this uploader:
if Rails.env.production?
storage :fog
else
storage :file
end
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Add a white list of extensions which are allowed to be uploaded.
def extension_whitelist
%w[jpg jpeg gif png]
end
end
Gemfile
group :production do
gem 'fog', '1.42'
end
carrierwave.rb
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV["S3_ACCESS_KEY"],
aws_secret_access_key: ENV["S3_SECRET_KEY"],
}
config.fog_directory = ENV["S3_BUCKET"]
end
end
Environment Variables
If you still want to manage your environmental variables, maybe this can come in handy:
Temporary:
export S3_ACCESS_KEY=[...]
export S3_SECRET_KEY=[...]
export S3_BUCKET=[...]
After setting them you can print them to check if they got set:
printenv
You can also unset the variables:
unset S3_ACCESS_KEY
unset S3_SECRET_KEY
unset S3_BUCKET
Permanent:
Edit the ~/.bashrc or ~/.bash_profile to set the environmental variables permanently.
Hope this helps, have a great day!
UPDATED
Declare your AWS credentials in one of your yml file (secrets.yml for example) like this:
AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ARTIFACTS_REGION: eu-central-1
ARTIFACTS_BUCKET: some_bucket
Don't forget to add the file with your credentials to .gitignore
Then use your credentials in the carrierwave config file (carrierwave.rb) like this:
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['ARTIFACTS_REGION']
}
UPDATED
To manage your environment variables easier try Figaro gem. Maybe it'll expose your actual problem and you'll solve it.
Usually this results from either the values not being set in env, or accidentally being mis-spelled.
There are a few possible ways to manage this, but in development the most direct way is with export, like this:
export S3_ACCESS_KEY=[...]
If you fill in the [...] portion with your value (and repeat for the three distinct variables), it should be able to find everything.
You can also check the current values of these by using echo like this:
echo $S3_ACCESS_KEY
If you have set the value correctly, it should print the value to your terminal. If the value is not set, it will just print an empty line (if there is an empty line for any of the values, it would result in the error you are seeing).

uninitialized constant AWS (NameError) after bundle update in Ruby

I'm now completely confused with AWS NameError after I updated bundle in Ruby. The command was bundle update.
The below is my Gemfile.lock
DEPENDENCIES
actionmailer_inline_css
aws-sdk
...
awesome_print (1.6.1)
aws-sdk (2.3.9)
aws-sdk-resources (= 2.3.9)
aws-sdk-core (2.3.9)
jmespath (~> 1.0)
aws-sdk-resources (2.3.9)
aws-sdk-core (= 2.3.9)
.
My Gemfile includes
gem 'aws-sdk'
However I have no idea why suddenly this problem occurred. Are there anyone having this issue before and ending up fixing this error? please share with me! I'm desperate to fix this problem..
I have aws.rb file in the initializers.
AWS.config(
#:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:access_key_id => 'XX',
#:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
:secret_access_key => 'X/X/X/X'
)
#S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET']]
S3_BUCKET = AWS::S3.new.buckets['XX']
Ruby version is 2.1.5
The entire error message when typing rails s is as follow:
/Users/sungpah/XX/config/initializers/aws.rb:1:in `<top (required)>': uninitialized constant AWS (NameError)
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
from /Users/sungpah/ringle/config/environment.rb:5:in `<top (required)>'
from /Users/sungpah/ringle/config.ru:3:in `block in <main>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /Users/sungpah/ringle/config.ru:in `new'
from /Users/sungpah/ringle/config.ru:in `<main>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:61:in `app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:78:in `start'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/sungpah/ringle/bin/rails:8:in `require'
from /Users/sungpah/ringle/bin/rails:8:in `<top (required)>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/sungpah/ringle/bin/spring:13:in `require'
from /Users/sungpah/ringle/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
The issue is you have to use "Aws" instead of "AWS" for version 2 AWS SDK see below use the below code. AWS SDK Version 2 uses the "Aws" namespace, not "AWS".
Aws.config(
#:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:access_key_id => 'XXXXXXXXX',
#:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
:secret_access_key => 'XXXXXXX'
)
#S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET']]
S3_BUCKET = Aws::S3.new.buckets['ringlecourse']
Also read this documentation for AWS SDK upgrades http://docs.aws.amazon.com/sdkforruby/api/
Change initialiser code inside aws.rb to
Aws.config.update({
credentials: Aws::Credentials.new(
ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
})
Reference
Upgrading from the Amazon AWS SDK v1 to v2 contains a few surprises. The most immediately impacting surprise is that the name AWS was changed to Aws, requiring code changes in order to simply update the gem.
The AWS SDK for Ruby - Version 2 guide will help with the details. The very first entry in this guide concerns the NameError: uninitialized constant AWS error that you encountered. An overview of the list of changes, features, and improvements of the AWS SDK v2 are documented in Announcing V2 of the AWS SDK for Ruby, and that's worth a read to know what to expect.
Note that you can continue using the AWS SDK v1 alongside the AWS SDK v2 gem if you like, simply by including both gems in your Gemfile:
gem 'aws-sdk', '~> 2'
gem 'aws-sdk-v1'
This will allow your existing code to work without changes. That's definitely a good thing. Note that to continue using the v1 gem, you have to now refer to it as aws-sdk-v1 in the Gemfile. This is a nice feature, and will allow you to migrate completely to the v2 gem on your own schedule, while still being able to use the new v2 features immediately.
Step back and consider whether you're fully aware of what's in the new gem, and why you want to upgrade. Once you do that, you may find that it's simply not the right time for an upgrade. New versions are not always better, and sometimes upgrading a component can heavily impact a project. Consider biting off a small research project to investigate the real impact of upgrading to the gem version; you may find that it's not even necessary, especially if you don't have requirements that make use exclusively of the new gem version's features.

Rails: Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)

This error has been asked about before but I have tried all the answers on here and none have worked.
I am trying to connect AWS s3 to rails:
and I am getting the error pasted at the bottom of this question.
carrierwave.rb:
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], # required
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], # required
region: ENV['AWS_REGION'], # optional, defaults to 'us-east-1'
}
config.fog_directory = 'discoveredfmyelpdemo' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
I used figaro for my environmental vaiables which installed successfully and created application.yml (Note hashes are to cover up key but are correct in file):
AWS_ACCESS_KEY_ID: "A########################SA"
AWS_SECRET_ACCESS_KEY: "ba####################st"
AWS_REGION: "Sydney"
development:
AWS_BUCKET: discoveredfmyelpdemo
production:
AWS_BUCKET: discoveredfmyelpdemo
I don't know why this should affect it but just in case I will give you my gem and uploader relevant file contents (I am new to ROR).
Avatar_Uploader.rb:
class AvatarUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Gemfile:
gem "fog-aws"
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
gem 'figaro', '1.0'
and this is the full error:
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.38.0/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.38.0/lib/fog/core/service.rb:268:in `handle_settings'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.38.0/lib/fog/core/service.rb:98:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.38.0/lib/fog/core/services_mixin.rb:16:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.38.0/lib/fog/storage.rb:27:in `new'
from /usr/local/rvm/gems/ruby-2.3.0/bundler/gems/carrierwave-98d73a935047/lib/carrierwave/uploader/configuration.rb:123:in `eager_load_fog'
from /usr/local/rvm/gems/ruby-2.3.0/bundler/gems/carrierwave-98d73a935047/lib/carrierwave/uploader/configuration.rb:136:in `fog_credentials='
from /home/ubuntu/workspace/config/initializers/fog.rb:2:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/bundler/gems/carrierwave-98d73a935047/lib/carrierwave/uploader/configuration.rb:158:in `configure'
from /usr/local/rvm/gems/ruby-2.3.0/bundler/gems/carrierwave-98d73a935047/lib/carrierwave.rb:14:in `configure'
from /home/ubuntu/workspace/config/initializers/fog.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:651:in `load_config_initializer'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `call'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
from /home/ubuntu/workspace/config/environment.rb:5:in `<top (required)>'
from /home/ubuntu/workspace/config.ru:3:in `require'
from /home/ubuntu/workspace/config.ru:3:in `block in <main>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /home/ubuntu/workspace/config.ru:in `new'
from /home/ubuntu/workspace/config.ru:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ubuntu/workspace/bin/rails:9:in `require'
from /home/ubuntu/workspace/bin/rails:9:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ubuntu/workspace/bin/spring:13:in `require'
from /home/ubuntu/workspace/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Thanks for your help.
application.yml
aws_access_key_id: "A########################SA"
aws_secret_access_key: "ba####################st"
aws_region: "Sydney"
development:
aws_bucket: discoveredfmyelpdemo
production:
aws_bucket: discoveredfmyelpdemo
and to access ENV['aws_access_key_id'] like that
Can you try the keys in yml files in small letters instead?

undefined method `has_attached_file' : Paperclip error with ActiveAdmin and cucumber

I have installed ActiveAdmin(1.0.0.pre1), Paperclip(4.2.1) and Cucumber(1.4.2).
I am facing strange issue in my system when I do testing with cucumber.
I have a model with paperclip configuration and has method has_attached_file. However everything is working well, but I do testing with cucumber it raises error regarding active admin resource of that model.
Here is full error stack :
undefined method `has_attached_file' for Document (call 'Document.connection' to establish a connection):Class (NoMethodError)
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
/home/anand/rails_workspace_20_1_2015/MyApp/app/models/document.rb:7:in `<class:Document>'
/home/anand/rails_workspace_20_1_2015/MyApp/app/models/document.rb:2:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:360:in `require_or_load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:494:in `load_missing_constant'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:184:in `const_missing'
/home/anand/rails_workspace_20_1_2015/MyApp/app/admin/document.rb:2:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:197:in `block in load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/error.rb:41:in `capture'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:197:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:189:in `block in load!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:189:in `each'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:189:in `load!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin/application.rb:211:in `routes'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bundler/gems/activeadmin-28e8a8f36640/lib/active_admin.rb:79:in `routes'
/home/anand/rails_workspace_20_1_2015/MyApp/config/routes.rb:2:in `block in <top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:410:in `draw'
/home/anand/rails_workspace_20_1_2015/MyApp/config/routes.rb:1:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `each'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/file_update_checker.rb:75:in `call'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/activesupport-4.2.1/lib/active_support/file_update_checker.rb:75:in `execute'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:427:in `each_strongly_connected_component_from'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:345:in `each'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:345:in `call'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/home/anand/.rvm/rubies/ruby-2.2.0-preview1/lib/ruby/2.2.0/tsort.rb:205:in `tsort_each'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-rails-1.4.2/lib/cucumber/rails/application.rb:15:in `initialize!'
/home/anand/rails_workspace_20_1_2015/MyApp/config/environment.rb:5:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-rails-1.4.2/lib/cucumber/rails.rb:7:in `require'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-rails-1.4.2/lib/cucumber/rails.rb:7:in `<top (required)>'
/home/anand/rails_workspace_20_1_2015/MyApp/features/support/env.rb:8:in `require'
/home/anand/rails_workspace_20_1_2015/MyApp/features/support/env.rb:8:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/rb_support/rb_language.rb:95:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/rb_support/rb_language.rb:95:in `load_code_file'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime/support_code.rb:180:in `load_file'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime/support_code.rb:82:in `each'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime.rb:184:in `load_step_definitions'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/runtime.rb:42:in `run!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/lib/cucumber/cli/main.rb:47:in `execute!'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/gems/cucumber-1.3.19/bin/cucumber:13:in `<top (required)>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bin/cucumber:23:in `load'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bin/cucumber:23:in `<main>'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in `eval'
/home/anand/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in `<main>'
Gemfile :
source 'https://rubygems.org'
gem 'devise'
gem 'mysql2'
gem 'cancancan'
gem 'activeadmin' , github: "activeadmin"
gem 'paperclip'
gem 'paper_trail'
gem 'rails', '4.2.1'
gem 'jquery-rails'
group :development, :test do
gem 'byebug'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'pry-rails'
gem 'pry-doc'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails', require: false
gem 'rspec-rails'
end
Model :
class Document < ActiveRecord::Base
belongs_to :user
has_paper_trail
has_attached_file :doc, :default_url => "/images/:style/missing.png"
validates_attachment :doc, content_type: {:content_type => ["application/pdf", /\Aimage\/.*\Z/ ] }
end
ActiveAdmin resource :
ActiveAdmin.register_page "Document" do
end
What is the reason to getting this problem ? I have tried searching all the resource from google and may other way to trace it. And finally I have posted here. Need suggestion. Thank you.
After checking all files and experiments, I finally found the solution. The problem was paperclip.rb file in Rails.root/lib folder. The file contains no content but it creates problem while I was running cucumber. So I deleted that file and all works. Let's hope this helps to other :-)

NoMethodError in undefined method `scoped' in rails (using ancestry gem)

I am using the ancestry gem and i m testing my model in the console first.When i use
root = Message.create(:content => "hello")
It inserts data into the database but when i use
child = root.children.create(:content => "hhjjh")
It gives an error.This is the log
NoMethodError: undefined method `scoped' for #<Class:0x007fa4a61182b0>
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/ancestry-1.2.3/lib/ancestry/instance_methods.rb:136:in `children'
from (irb):2
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:90:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/chat/bin/rails:8:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:183:in `block in serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `fork'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:131:in `block in run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `loop'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I don't know what i m doing wrong but i think this is suppose to work.Any ideas?
It looks like your version of Ancestry is 1.2.3 or something. Updating to a new version looks like it should fix that problem.
Gemfile
gem 'ancestry', '~> 2.1'

Resources