3
我真的卡在這裏,我不知道發生了什麼事。CarrierWave拋出NoMethodError - 未定義的方法`新'的「文件」:字符串:
我試圖上傳的圖像,但是當我提交表單,我得到的錯誤:
Started PATCH "/partners/3" for ::1 at 2015-10-19 14:44:45 -0400
Processing by PartnersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CELmC1ibFcHCYB0avQk632KZzqvLUb125W2b3F2At3pkeAaL7N/aowlGqrd/+vaFV/RZ78z+/lmJc60hNPtrCw==", "partner"=>{"name"=>"Company", "description"=>"We make stuff", "track_id"=>"3"}, "commit"=>"Update Partner", "id"=>"3"}
Partner Load (0.1ms) SELECT "partners".* FROM "partners" WHERE "partners"."id" = ? LIMIT 1 [["id", 3]]
(0.0ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.2ms)
NoMethodError - undefined method `new' for "file":String:
carrierwave (0.10.0) lib/carrierwave/uploader/store.rb:106:in `storage'
carrierwave (0.10.0) lib/carrierwave/uploader/proxy.rb:35:in `identifier'
carrierwave (0.10.0) lib/carrierwave/mount.rb:312:in `write_identifier'
carrierwave (0.10.0) lib/carrierwave/mount.rb:223:in `write_logo_img_identifier'
activesupport (4.2.3) lib/active_support/callbacks.rb:430:in `block in make_lambda'
activesupport (4.2.3) lib/active_support/callbacks.rb:162:in `block in halting'
activesupport (4.2.3) lib/active_support/callbacks.rb:502:in `block in call'
activesupport (4.2.3) lib/active_support/callbacks.rb:502:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
activerecord (4.2.3) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.2.3) lib/active_record/persistence.rb:120:in `save'
activerecord (4.2.3) lib/active_record/validations.rb:37:in `save'
activerecord (4.2.3) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.2.3) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
activerecord (4.2.3) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
這是在控制器中的一部分,其中其引發錯誤:
# PATCH/PUT /partners/1
# PATCH/PUT /partners/1.json
def update
respond_to do |format|
>>> HERE >>> if @partner.update(partner_params)
format.html { redirect_to @partner, notice: 'Partner was successfully updated.' }
format.json { render :show, status: :ok, location: @partner }
else
format.html { render :edit }
format.json { render json: @partner.errors, status: :unprocessable_entity }
我的合作伙伴查看:
<div class="form-group">
<%= f.label :logo_img %>
<%= f.file_field :logo_img %>
</div>
型號:
class Partner < ActiveRecord::Base
belongs_to :track
has_one :question
validates :name, :presence => true
validates :track_id, :presence => true
mount_uploader :logo_img, ImageUploader
end
我真的很呆在這裏,並希望得到任何幫助/評論/輸入...
感謝
你可以包含ImageUploader的代碼嗎?和 - 你的表單中是否有'html:{multipart:true}'屬性(上傳文件時有必要)? – basiam
是的 - 我實際上只是在兩秒鐘之前才發現它....查看答案 – mhz