我有一个多对多关系 Explaination 和 Topic,创建 Explaination 绑定若干 Topics,其他的都对了,就是这个关联一直绑不上,日志说 Unpermitted parameters: topic_ids,请问这是啥情况,知道请指点,谢啦先!
我的 Controller 是这样写的
def create
params.permit!
@place = Place.find(params[:place_id])
@explaination = @place.explainations.create(params[:explaination].permit(:title, :speaker, :speaker_title, :like, :topic_ids))
@explaination.save
redirect_to @place
end
其他相关代码如下
class Explaination < ActiveRecord::Base
belongs_to :place
has_many :explaination_segments, :dependent => :destroy
has_and_belongs_to_many :topics
def segments
self.explaination_segments
end
end
class Topic < ActiveRecord::Base
belongs_to :place
has_and_belongs_to_many :explainations
end
create_table "explainations_topics", force: true do |t|
t.integer "explaination_id"
t.integer "topic_id"
t.datetime "created_at"
t.datetime "updated_at"
end