speichern Ich versuche, Checkbox, Daten in ProjekttabelleKann nicht check_box_tag Daten mit has_many durch
In Project Controller
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
Im Projekt neue Ansicht
<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
Auf meinen Logs ich zu retten tag_ids Parameter wie folgt
project"=>{"tag_ids"=>["1", "2"]}
Frage: Muss ich die Daten separat in die Tagging-Tabelle speichern oder speichert sie aufgrund der Assoziationen in der Tabelle automatisch Daten?
Momentan wird nichts in der Tagging-Tabelle gespeichert. Wie kann ich Tagging-Daten speichern?
'tag_ids' soll in welcher Tabelle gespeichert werden? Assoziationen speichern keine Daten in verwandter Tabelle. Sie können 'accepts_nested_attributes_for' verwenden. – dp7
On Tagging Tabelle – Newbie
Ich habe accessed_nested_attributes_for on Tagging-Tabelle hinzugefügt, aber immer noch nothings saving ... – Newbie