どうしたのみんな!
Rails (4) アプリケーションに関連付け has_and_belongs_to_many を実装しようとしています。これが私のコードです:
マイ カテゴリ モデル
class Admin::Category
include Mongoid::Document
...
has_and_belongs_to_many :estimates, class_name: "User::Estimate", :inverse_of => :categories
end
私の見積もりモデル
class User::Estimate
include Mongoid::Document
...
has_and_belongs_to_many :categories, class_name: "Admin::Category", :inverse_of => :estimates
end
強いパラメータ
def user_estimate_params
params.require(:user_estimate).permit({:category_ids => []}, :favorite_time, :city_id, :number_of_guests, :event_date, :stage_where_it_is, :event_type, :observation, user_attributes:[:name, :email, :receive_news, :password, :password_confirmation, :preferred_phone, :alternate_phone])
end
私の要求
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JJk6m+5VV7tCLDeUCRkQatQOw/fFiw8LCV39casua+c=", "user_estimate"=>{"user_attributes"=>{"email"=>"user@email.com"}, "city_id"=>"523b638b5383de1887000001", "event_type"=>"Casamento", "number_of_guests"=>"456", "event_date"=>"21/11/2013", "stage_where_it_is"=>"Nos próximos 30 dias", "category_ids"=>["523b667687924d211527530e", "523b667b87924d2115275317"], "observation"=>""}, "event_type_select"=>"527ace4353455263c9000000", "commit.x"=>"149", "commit.y"=>"40"}
Unpermitted parameters: category_ids
ご覧のとおり、Unpermitted parameters: category_idsというエラーが表示され、カテゴリが強力なパラメータ メソッドに既に追加されていても、カテゴリを保存できません。
MongoDB/Mongoid を使用しています。
同様の質問をたくさん見つけましたが、これらの質問は => [] を追加して解決されました
すでに行ったように、強力なパラメーター メソッドに。
何か助けはありますか?
乾杯