我接受,即使我有田野以下錯誤在attr_accessible更新屬性導致質量分配例外,甚至attr_accessible
Can't mass-assign protected attributes: utf8, _method, authenticity_token, profile, commit, action, controller, id
更新我猜,我不想其他屬性保存正在引發異常,但我怎樣才能濾除它們?
這是params哈希表
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"1aabj2DxleZoDu/U0SzGXSZrPcesRKXkIXTRVbk9f0A=",
"profile"=>{"name"=>"Aaron Dufall",
"company"=>"Supreme Windows",
"location"=>"",
"professional_bio"=>""},
"commit"=>"Update",
"id"=>"1"}
profiles_controller.rb
class ProfilesController < ApplicationController
respond_to :html
def edit
@profile = Profile.find(params[:id])
respond_with @profile
end
def update
@profile = Profile.find(params[:id])
if @profile.update_attributes(params)
flash[:success] = "Profile sucessfully updated"
redirect_to root_path
else
flash[:error] = "Profile failed to update"
render 'edit'
end
end
end
profile.rb