Ruby on rails 无法保存已通过的复选框标记数据

Ruby on rails 无法保存已通过的复选框标记数据,ruby-on-rails,checkbox,sqlite,nested-attributes,has-many-through,Ruby On Rails,Checkbox,Sqlite,Nested Attributes,Has Many Through,我正在尝试在项目表中保存复选框数据 项目内控制员 def new @project = Project.new @allTags = Tag.all @allBenefits = Benefit.all end def create p params[:projectName]; # this always throws nil even there is a value @project = Project.new(project_para

我正在尝试在项目表中保存复选框数据

项目内控制员

 def new
    @project = Project.new
    @allTags = Tag.all
    @allBenefits = Benefit.all
  end



 def create
    p params[:projectName]; # this always throws nil even there is a value
    @project = Project.new(project_params)
    #@tagging = @project.tagging.create!(:project=>Project.id,:tag=>1)

    if @project.save
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end

  def project_params
     params.require(:com_a_b_c_project).permit(:projectName, :briefDesc, :whatSection, :challengers, :status, :valueProposal, :maturityLevel,:tag_ids =>[])
  end
在项目新视图中

<h4><label for = "tags">Tags</label></h4>

<% @allTags.each do |tag| %>
    <p><%= f.label tag.tagName %></p>
    <%= check_box_tag :tag_ids, tag.id, @project.tags.include?(tag), :name => 'project[tag_ids][]'-%>
 <%end%>



class Com::a::b::c::Project < ActiveRecord::Base
     has_many :taggings 
     has_many :tags, :through => :taggings
     accepts_nested_attributes_for :tags 
    end

class Com::a::b::c::Tag < ActiveRecord::Base
  has_many :taggings 
 has_many :projects, :through => :taggings
end


class Com::a::b::c::Tagging < ActiveRecord::Base
  belongs_to :project
  belongs_to :tag
end
问:我必须单独将数据保存到标记表中,还是因为表中的关联,它会自动保存数据

当前标记表上未保存任何内容。如何存储标记数据?

如果我正确遵循

class Com::a::b::c::Project < ActiveRecord::Base
 has_many :taggings 
 has_many :tags, :through => :taggings
 accepts_nested_attributes_for :tags 
end
class Com::a::b::c::Project:标记
接受:标记的\u嵌套\u属性\u
结束

在项目模型上,应该允许将其持久化。

标记ID
应该保存在哪个表中?关联不在相关表中存储数据,您可以使用
accepts_nested_attributes_for
我已经为标记表添加了accepts_nested_attributes_,但仍然没有保存任何内容…通过添加@project.taggings.build to projects控件,将accepts_nested_attributes_添加到最终存储了带有项目id的记录的模型中。但是标记id仍然没有存储在标记中表。我已将建议添加到Project ActiveRecord中。但还是没有什么能坚持下去
class Com::a::b::c::Project < ActiveRecord::Base
 has_many :taggings 
 has_many :tags, :through => :taggings
 accepts_nested_attributes_for :tags 
end