【发布时间】:2015-01-25 02:09:33
【问题描述】:
我正在尝试使用 has_many 将 cmets 排序到事件中:通过使用复选框的关联,但是未保存所选事件。这是我的模型:
class Comment < ActiveRecord::Base
has_many :categorizations
has_many :events, :through => :categorizations
end
class Event < ActiveRecord::Base
has_many :categorizations
has_many :comments, :through => :categorizations
end
class Categorization < ActiveRecord::Base
belongs_to :comment
belongs_to :event
end
我的 cmets 表单如下所示:
<%= simple_form_for [@post, @comment] do |f| %>
<%= f.input :title %>
<%= f.association :events, :as => :check_boxes %>
<%= f.submit "Save" %>
阅读 this answer 后,我将其添加到我的事件和评论控制器中,但没有运气:
def comment_params
params.require(:comment).permit(:post_id, :title, :categorization_ids => [])
end
【问题讨论】:
标签: ruby-on-rails