编辑2~
大家好,
我通过根据这个更改我的模型文件解决了我以前的新错误。我不知道为什么,但它解决了它。我现在有这个错误要处理。: |
没有钥匙?我的控制器中的方法。我需要包括它吗?如果是这样,怎么做?
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/”中的所有相关文件夹上传到 s3上的存储桶 choco_photos 中的文件夹“images”中。我还更改了 URL 和 PATH 以反映它,但我很确定我做错了什么。
PATH AND URL 文件是否反映了图像在 S3 上的存储和访问位置?
我会提到,即使在看了回形针上的 railscast 之后,我仍然对配置感到困惑。我查看了 AWS 推荐的文档,但没有帮助。具体来说,我对这种说法感到困惑:
# 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
~
这是我的宝石文件:
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'
编辑结束