人家怎么了!
我一直在尝试在我的 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。
我发现了很多类似的问题,但这些问题已经解决了添加=> []
对于强参数方法,正如我已经完成的那样。
有什么帮助吗?
干杯