このエラーが発生する理由を見つけようとして、インターネット全体を見てきました。Rails 3.2.7 で paperclip gem を使用してファイルをアップロードしようとすると、次のエラーが発生します。
undefined method `match' for nil:NilClass
完全なトレース:
paperclip (3.1.3) lib/paperclip/content_type_detector.rb:60:in `type_from_file_command'
paperclip (3.1.3) lib/paperclip/content_type_detector.rb:16:in `detect'
paperclip (3.1.3) lib/paperclip/io_adapters/file_adapter.rb:14:in `cache_current_values'
paperclip (3.1.3) lib/paperclip/io_adapters/file_adapter.rb:5:in `initialize'
paperclip (3.1.3) lib/paperclip/io_adapters/registry.rb:29:in `new'
paperclip (3.1.3) lib/paperclip/io_adapters/registry.rb:29:in `for'
paperclip (3.1.3) lib/paperclip/attachment.rb:424:in `post_process_style'
paperclip (3.1.3) lib/paperclip/attachment.rb:414:in `block in post_process_styles'
paperclip (3.1.3) lib/paperclip/attachment.rb:413:in `each'
paperclip (3.1.3) lib/paperclip/attachment.rb:413:in `post_process_styles'
paperclip (3.1.3) lib/paperclip/attachment.rb:406:in `block (2 levels) in post_process'
activesupport (3.2.6) lib/active_support/callbacks.rb:403:in `_run__920381213__photo_post_process__992575804__callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.6) lib/active_support/callbacks.rb:385:in `_run_photo_post_process_callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
paperclip (3.1.3) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.1.3) lib/paperclip/attachment.rb:405:in `block in post_process'
activesupport (3.2.6) lib/active_support/callbacks.rb:403:in `_run__920381213__post_process__992575804__callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.6) lib/active_support/callbacks.rb:385:in `_run_post_process_callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
paperclip (3.1.3) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.1.3) lib/paperclip/attachment.rb:404:in `post_process'
paperclip (3.1.3) lib/paperclip/attachment.rb:108:in `assign'
paperclip (3.1.3) lib/paperclip.rb:196:in `block in has_attached_file'
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.6) lib/active_record/base.rb:498:in `initialize'
app/controllers/products_controller.rb:51:in `new'
app/controllers/products_controller.rb:51:in `create'
actionpack (3.2.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.6) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.6) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.6) lib/active_support/callbacks.rb:414:in `_run__665893862__process_action__149004116__callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.6) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.6) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.6) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.6) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.6) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.6) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.6) lib/action_controller/metal/params_wrapper.rb:206:in `process_action'
activerecord (3.2.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.6) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.6) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.6) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.6) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.6) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.6) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.6) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.6) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.6) lib/action_dispatch/routing/route_set.rb:600:in `call'
actionpack (3.2.6) 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:35:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.6) 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.6) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.6) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `_run__460361433__call__992575804__callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.6) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.6) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.6) 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.6) 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.6) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.6) lib/rails/engine.rb:479:in `call'
railties (3.2.6) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.6) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
パラメーター:
{"utf8"=>"✓",
"authenticity_token"=>"xtsOzMtMakASXFhB3M27+DPRaJ8QIHs5EUSlualDul8=",
"product"=>{"name"=>"Colchão Ortobom de Espuma D45 Light Saúde Selado OrtoPillow",
"category_id"=>"1",
"subcategory_id"=>"1",
"maker"=>"Ortobom",
"dimension"=>"Colchões de Solteiro - 0,
78 x 1,
88 - Para Cama Box de 0,
78 x 1,
88",
"description"=>"Muito bom",
"photo"=>#<ActionDispatch::Http::UploadedFile:0x4184a60 @original_filename="Colchao_Ortobom_de_Espuma_D45.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"product[photo]\"; filename=\"Colchao_Ortobom_de_Espuma_D45.jpg\"\r\nContent-Type: image/jpeg\r\n",
@tempfile=#<File:C:/Users/Bernardo/AppData/Local/Temp/RackMultipart20120801-5212-kxcw51>>},
"commit"=>"Create Product"}
製品:
class Product < ActiveRecord::Base
belongs_to :category
belongs_to :subcategory
attr_accessible :description, :dimension, :maker, :name, :category_id, :subcategory_id, :photo
validates_presence_of :name, :maker, :dimension, :description, :category
has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
end
形:
<%= form_for(@product, :html => { :multipart => true } ) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :category %><br />
<%= f.collection_select(:category_id, Category.all, :id, :name, {:prompt => true}, :include_blank => false ) %> </p>
</div>
<div class="field">
<%= f.label :subcategory %><br />
<%= f.collection_select(:subcategory_id, Subcategory.all, :id, :name, {:prompt => true}, :include_blank => true ) %> </p>
</div>
<div class="field">
<%= f.label :maker %><br />
<%= f.text_field :maker %>
</div>
<div class="field">
<%= f.label :dimension %><br />
<%= f.text_field :dimension %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.file_field :photo %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
コントローラ:
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
end
end
# GET /products/1
# GET /products/1.json
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @product }
end
end
# GET /products/new
# GET /products/new.json
def new
@product = Product.new
if params[:category]
@product.category = Category.find(params[:category])
end
if params[:subcategory]
@product.subcategory = Subcategory.find(params[:subcategory])
end
respond_to do |format|
format.html # new.html.erb
format.json { render json: @product }
end
end
# GET /products/1/edit
def edit
@product = Product.find(params[:id])
end
# POST /products
# POST /products.json
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render json: @product, status: :created, location: @product }
else
format.html { render action: "new" }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# PUT /products/1
# PUT /products/1.json
def update
@product = Product.find(params[:id])
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product = Product.find(params[:id])
@product.destroy
respond_to do |format|
format.html { redirect_to products_url }
format.json { head :no_content }
end
end
end
他に何を試すべきかわかりません。私は知っていることはすべてやったが、何か間違ったことをしている. お役に立てれば幸いです。