在rails控制台上访问Paperclip模块方法

时间:2015-11-13 17:02:29

标签: ruby-on-rails ruby paperclip

我想访问有权访问我的Rails应用中配置的S3存储桶的s3_bucket方法。

查看Paperclip源代码我可以看到它位于Paperclip :: Storage :: S3(source code)模块下。

我已在每个环境中配置了Paperclip:

config/environments/development.rb

  config.paperclip_defaults = {
    :storage => :s3,
    # :s3_host_name => 'REMOVE_THIS_LINE_IF_UNNECESSARY',
    :bucket => 'educartis-development',
    s3_host_alias: "educartis-production.s3.amazonaws.com",
    url: ":s3_alias_url"
  }

这就是我从bundle exec rails c尝试的内容:

irb(main):008:0> Paperclip::Storage::S3.bucket_name
NoMethodError: undefined method `bucket_name' for Paperclip::Storage::S3:Module
    from (irb):8
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /Users/borjagvo/MyStuff/webdev/Work/Gemfeed/dev/repos/educartis/bin/rails:8:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/commands/rails.rb:6:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/command_wrapper.rb:38:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:183:in `block in serve'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:156:in `fork'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:156:in `serve'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:131:in `block in run'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `loop'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.4.0/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'

为什么要给undefined

1 个答案:

答案 0 :(得分:0)

看起来你是从互联网上的某个地方复制过来的,包括他们的提示(它在pry(main)>部分窒息)。启动控制台后,只需输入:

Paperclip::Storage::S3.bucket_name

然后,您完成的提示应如下所示:

irb(main):004:0> Paperclip::Storage::S3.bucket_name