2012-05-12 10 views
10

多段階のフォームで作業しています(Wicked gemを使用)。フォームの最初のカップルステップでは、私はユーザーモデルを編集しており、それらのステップはうまくいきます。次に、ユーザーモデルとのHABTM関係を持つ「関心」モデルを試します。しかし、私はこのエラーを取得:Railsエラー:保護属性を大量に割り当てることができません:interest_ids?

ActiveModel::MassAssignmentSecurity::Error in UserStepsController#update 

Can't mass-assign protected attributes: interest_ids 
Rails.root: /Users/nelsonkeating/rails_projects/Oreminder1 

Application Trace | Framework Trace | Full Trace 
app/controllers/user_steps_controller.rb:12:in `update' 

user_steps_controller.rb

class UserStepsController < ApplicationController 
    include Wicked::Wizard 
    steps :standard, :personal, :interests, :dates 

def show 
    @user = current_user 
    render_wizard 
end 

def update 
    @user = current_user 
    @user.attributes = params[:user] 
render_wizard @user 
end 

end 

相続ビュー:

<%= render layout: 'form' do |f| %> 

<% for interest in Interest.find(:all) %> 
<label class="checkbox"> 
    <%= check_box_tag "user[interest_ids][]", interest.id, @user.interests.include?(interest) %> 
    <%= interest.name %> 
</label> 
<% end %> 

<% end %> 

任意のアイデア?ありがとう!

+1

Rails 3.2.3以降であれば、一括割り当てするものを明示的にホワイトリストする必要があります。それが問題だろうか? http://www.h-online.com/security/news/item/Rails-3-2-3-make-mass-assignment-change-1498547.htmlを参照してください。 –

+0

私はそれを自分の興味モデルに設定しました: attr_accessible:name、:interest_ids – js111

+0

あなたのユーザーモデルに設定する必要があります。 – Mischa

答えて

21

は、あなたのユーザモデルにこれを追加することによって、このエラーを取り除くことができます。このinterest_ids属性はmass assignmentから保護されていて、とにかくそれに値を代入しようとすると、例外がスローされなければ

attr_accessible :interest_ids 

関連する問題