RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: nguyenj
Site: http://jnguyen.me/
Can you show an example without using Virtus?
I'm on rails4 ruby2.1 and I can't seem to get the tagging table to record the association. Any help will be much appreciated. (doing this from scratch)
# records.rb has_many :taggings has_many :tags, through: :taggings def tag_list tags.map(&:name).join(", ") end def tag_list=(names) self.tags = names.split(",").map do |n| Tag.where(name: n.strip).first_or_create! end end
# tagging.rb belongs_to :record belongs_to :tag
# tag.rb has_many :taggings has_many :records, through: :taggings
# views/records/_form.html.erb <div class="field"> <%= f.label :tag_list %><br /> <%= f.text_field :tag_list %> </div>
# records_controller.rb def record_params params.require(:record).permit(:name, :tag_list) end
The tags do get created in the tag table; but no association defined in the tagging table between the record and the tag.
How did you deal with your form post? Was it to events_comments_path or events_pictures_comments_path?
Can you show an example without using Virtus?
I'm on rails4 ruby2.1 and I can't seem to get the tagging table to record the association. Any help will be much appreciated. (doing this from scratch)
The tags do get created in the tag table; but no association defined in the tagging table between the record and the tag.
How did you deal with your form post? Was it to events_comments_path or events_pictures_comments_path?