Heroku NoMethodError - Paperclip

时间:2012-04-10 21:39:32

标签: ruby-on-rails heroku paperclip

EDIT2〜

大家好,

我根据this更改了我的模型文件,解决了以前的新错误。我不知道为什么,但它解决了它。我现在有这个错误要处理。 :|

没有钥匙?我的控制器中的方法。我需要包含它吗?如果是这样,怎么样?

NoMethodError in ProductPhotosController#index

undefined method `key?' for nil:NilClass
Rails.root: /Users/cj3kim/Desktop/rails_projects/chocosite

以下是完整的跟踪:

actionpack (3.2.2) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.2) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.2) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.2) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:115:in `process'
actionpack (3.2.2) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.2) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `dispatch'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:594:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in     `_run__3068104272435367366__call__4006997629250885704__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/static.rb:61:in `call'
railties (3.2.2) lib/rails/engine.rb:479:in `call'
railties (3.2.2) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Users/cj3kim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/cj3kim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/cj3kimactionpack (3.2.2) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.2) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.2) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.2) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:115:in `process'
actionpack (3.2.2) lib/abstract_controller/rendering.rb:45:in `process'  
actionpack (3.2.2) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `dispatch'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:594:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in     `_run__3068104272435367366__call__4006997629250885704__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/static.rb:61:in `call'
railties (3.2.2) lib/rails/engine.rb:479:in `call'
railties (3.2.2) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Users/cj3kim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/cj3kim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/cj3kim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in    start_thread'/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

这是我的控制器:

1 class ProductPhotosController < ApplicationController
2   # GET /product_photos
3   # GET /product_photos.json
4   def index
5     @product_photos = ProductPhoto.all
6 
7     respond_to do |format|
8       format.html # index.html.erb
9       format.json { render json: @product_photos }
10     end
11   end

这是我的模特:

1 class ProductPhoto < ActiveRecord::Base
2   has_attached_file :image,
3     :style => {:small => "150x150"},
4     :storage => :s3,
5     :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
6     :path => "chocosite/:attachment/:style/:id.:extension"
7 end

结束修改


修改〜

Heroku加载错误 - 回形针

问题是我在模型中发现的语法错误。我现在有一个新问题

我做了什么:

此问题发生在本地主机上,sqlite3为db。我登录到s3模块并将曾经在'public / system / images / 000/000 /'中的所有相关文件夹上传到文件夹'images' s3上的桶choco_photos。我也改变了URL和PATH以反映它,但我很确定我做错了什么。

PATH和URL文件是否反映了在S3上存储和访问图像的位置?

我会提到即使看完回形针上的railscast,我仍然对配置感到困惑。我查看了AWS推荐的文档,但it没有帮助。具体而言,我对此声明感到困惑:

# File 'lib/paperclip/storage/s3.rb', line 203

def s3_object style_name = default_style
  s3_bucket.objects[path(style_name).sub(%r{^/},'')]
end

感谢任何和所有帮助。

更多信息:

LoadError in Product_photos#index

Showing /Users/cj3kim/Desktop/rails_projects/chocosite/app/views/product_photos/index.html.erb where line #4 raised:

cannot load such file -- aws-sdk (You may need to install the aws-sdk gem)
Extracted source (around line #4):

1: <div id="container_product_photos"> 
2: <% @product_photos.each do |photo| %>
3:   <div class="product_box" >
4:     /*#<%= link_to image_tag(photo.image.url(:small)), product_photo_path(photo) %>*/
5:     <p class='description'><%= photo.Name %> </p>
6:   </div> 
7: <% end %>

这是我的模型文件:

1 class ProductPhoto < ActiveRecord::Base
2   has_attached_file :image,
3     :storage => :s3,
4     :s3_credentials => {
5       :access_key_id => ENV['Access Key'],
6       :secret_access_key => ENV['Secret Key']
7     },
8     :bucket => ENV['choco_photos'],
9     :style => {
10       :small => "150x150"
11     },
12     :url => "/images/:id/:style/:basename.:extension",
13     :path => "/images/:id/:style/:basename.:extension"
14 end

这是我的gemfile:

12 group :production do
13     gem 'pg'
14 end
15 
16 gem 'bootstrap-sass', '2.0.0'
17 gem 'paperclip', '~> 3.0'
18 gem 'aws-sdk', '~> 1.3.4'

编辑结束


1 个答案:

答案 0 :(得分:0)

对于问题1:Heroku在Cedar堆栈上运行1.9.2,根据您应用的URL,您可以使用它。我相信1.9.1只是一个目录,并没有真正与版本相关...我在文件夹名称中的1.9.1和我的系统实际运行1.9.2或1.9.3之间得到了相同的“不匹配”(和我只通过RVM运行1.9.2或1.9.3)。

您可以通过在heroku上打开Rails控制台来验证Heroku版本。

  1. 打开终端/控制台
  2. 导航到您的项目目录
  3. 类型:heroku运行控制台(假设您已经安装了heroku gem或CLI工具)
  4. 控制台加载后,键入:RUBY_VERSION(您应该看到1.9.2或1.9.3输出)
  5. 对于问题2:我必须改变我在Gemfile中使用回形针的方式。我使用它,它适用于Cedar:

    gem 'paperclip', "~> 3.0"
    gem "aws-sdk"
    

    在我的相关模型中:

    has_attached_file :photo,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :styles => {
                        :large => "600x480",
                        :medium => "330x230",
                        :small => "210x150",
                        :thumb => "90x90"
                    },
                    :path => 'images/products/:style/:filename'
    

    在我的s3.yml文件中:

    development: 
    access_key_id: MYKEY
    secret_access_key: MYSUPERSECRETACCESSKEY
    bucket: bucketname
    

    希望有所帮助!