I would like to assign two โtagโ models (sector categories and free labeling) to company models using act_as_taggable_on . NB: I am new to RoR!
This is easy to do if you just use standard text input fields, but I would like to use checkboxes for one type (a predefined category tag of a fixed sector), and then allow the user to add tags separated by commas in the input field.
I played with this problem in different ways ... inspired by this question ... but I can't get it to work
Here is what I still have:
# models/company.rb class Company ... acts_as_taggable_on :tags, :sectors has_many :taggings, :as => :taggable, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging", :conditions => { :taggable_type => "Company" } has_many :sector_tags, :through => :taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag", :conditions => {:context => "sectors"} end
in the form (using the pearl simple_form) I have ...
# views/companies/_form.html.haml = simple_form_for @company do |f| = f.input :name = f.association :sector_tags, :as => :check_boxes, :hint => "Please click all that apply" = f.input :tag_list = f.button :submit, "Add company"
And in my company controller I
But this causes a validation error:
ActiveRecord::RecordInvalid in CompaniesController
Can anyone hint how can I do this correctly?
A related question is, is this a good way to do this at all? Would I be better off using a category model to assign sector tags through a collaborative model?
Thanks!
ruby-on-rails associations simple-form acts-as-taggable-on
kbjerring
source share