2012-03-22 4 views
0

私はバックボーンを使用していて、新しいオブジェクトを作成しようとしていますが、このエラーが発生しています。レールは気にしない属性を無視すると思った。つまり、本物のトークンが自分のオブジェクトに追加しようとしていません。バックボーン/レール - ビルド(params [...])ActiveRecord :: UnknownAttributeErrorを発生させます

マイコントローラ:

def create 
    page = Page.find(params[:page_id]) 
    branch = page.page_branches.build(params[:page_branch]) 
    branch.form = page.form 
    if branch.valid? 
    page.page_branches << branch 
    redirect_to(edit_page_path(page, :anchor => "branch-panel")) 
    else 
    raise "#{branch.errors.map}" 
    end 
end 

エラー:以下の応答へ

Processing by PageBranchesController#create as JSON 
Parameters: {"page_branch"=>{"next_page_id"=>"KS5ad82889e04e5806e0455d5a81e81a9511", 
"description"=>"linking", "utf8"=>"", "authenticity_token"=>"", "id"=>nil, 
"page_id"=>"KS000c29724a16-u-2TQMP57-gYm-U", "trigger_type"=>"Always", 
"base_options"=>"AllowAnonymous;BASE", 
"question_options"=>"KS000c29724a16CfC2TQUL1--gxG-U", "keyword_options"=>"", 
"qualification"=>"", "commit"=>""}, "page_id"=>"KS000c29724a16-u-2TQMP57-gYm-U"} 
WARNING: Can't mass-assign protected attributes: id 
Completed 500 Internal Server Error in 239ms 

ActiveRecord::UnknownAttributeError (unknown attribute: utf8): 
    app/controllers/page_branches_controller.rb:21:in `create' 

ありがとう:

は、私は私のレールのモデルにattr_accessibleを追加しました:

attr_accessible :page_id, :page_name, :next_page_id, :next_page_name, 
       :description, :trigger_type, :internal_qualification, 
       :order, :form_id, :qualification 

そうすることでで、私は次の警告を得るが、ビルドが提供されるつもりハッシュの全てのキー/値のペアを使用しようとされて

WARNING: Can't mass-assign protected attributes: utf8, authenticity_token, id, base_options, question_options, keyword_options, commit 

答えて

1

ActiveRecordの質量の割り当てを成功し、昇給 UnknownAttributeError unknown attributes are supplied via mass assignment

おそらくthis codeをチェックすると、私が言っていることを確認するのに役立ちます。

私は次の2つのオプションがあると思う:質量割り当てでそれを使用する前params[:page_branch]をクリーンアップするには

  1. を。
  2. サーバーに奇妙な属性を送信しないようにBackbone.YourModel.toJSON()を変更します。
関連する問題