我有...爲什麼回形針給我這個「未知屬性」錯誤?
/config/routes.rb:
resources :surveys do
resources :screenshots
end
/app/models/survey.rb:
has_many :screenshots
/應用/型號/screenshot.rb:
attr_accessible :name, :shot, :screenshot, :result_ids
belongs_to :survey
has_many :results
has_attached_file :shot, :default_url => ActionController::Base.helpers.asset_path('missing_:style.png')
/db/schema.rb:
create_table "screenshots", :force => true do |t|
t.integer "survey_id"
t.boolean "resetting_cache", :default => false
t.string "url"
t.string "shot_file_name"
t.string "shot_content_type"
t.integer "shot_file_size"
t.datetime "shot_updated_at"
t.boolean "include", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
end
/app/controllers/screenshots_controller.rb:
def new
@survey = Survey.find(params[:survey_id])
@competitor = @survey.competitor
@screenshot = Screenshot.new
end
def create
@survey = Survey.find(params[:survey_id])
@screenshot = Screenshot.new(params[:screenshot])
@competitor = @survey.competitor
flash[:notice] = "Screenshot was successfully added." if @screenshot.save
respond_with(@survey, @screenshot)
end
/app/views/screenshots/_form.html.haml:
= simple_form_for [@survey, @screenshot] do |f|
= f.error_notification
= f.file_field :shot
= f.association :results, :collection => @survey.selected_results
= f.button :submit, :label => "Save", :id => "submit_screenshot"
有誰知道爲什麼@screenshot = Screenshot.new(params[:screenshot])
給我一個unknown attribute: screenshot
錯誤?
典型params
在這一點上應該是:
=> {"utf8"=>"✓",
"authenticity_token"=>"t33SO+/mpPlQY/+7+5iRTe6O2zL/MtqisYXyghzkLY8=",
"screenshot"=>
{"screenshot"=>
#<ActionDispatch::Http::UploadedFile:0x007fd5cca0ace0
@content_type="image/png",
@headers=
"Content-Disposition: form-data; name=\"screenshot[screenshot]\"; filename=\"youtube.png\"\r\nContent-Type: image/png\r\n",
@original_filename="youtube.png",
@tempfile=
#<File:/var/folders/k9/vnpft_6d7qs6xmdb9_4svvmw0000gn/T/RackMultipart20131125-3030-1gmx1sy>>,
"result_ids"=>["", "29857"]},
"commit"=>"Create Screenshot",
"action"=>"create",
"controller"=>"screenshots",
"survey_id"=>"14564"}
thx - 修復它 –