I was wondering if someone can help me understand this part in the documentation:
With the defined context in model, you have multiple new methods at disposal to manage and view the tags in the context. For example, with :skill context these methods are added to the model: skill_list(and skill_list.add, skill_list.remove skill_list=), skills(plural), skill_counts.
I have this:
model:
class Project < ActiveRecord::Base
acts_as_taggable # Alias for acts_as_taggable_on :tags
acts_as_taggable_on :item
end
controller:
def project_params
params.require(:project).permit(
:user_id, :tag_list)
end
view
<%= f.text_field :tag_list %> <!-- wrapped in a simple_form -->
So my question is... does that mean, if I have :items
in my model, I can replace all the :tag_list
into :item_list
? And just use item_list from now on? I tried this, but its not producing the same results as what I currently have... maybe I messed up somewhere, but is this "theoretically" correct?
Thanks
BONUS:
So eventually, if I have more than one thing that I want to tag:
acts_as_taggable_on :item, :more_taggable_item
I can have this in my strong params
params.require(:project).permit(
:user_id, :tag_list, :more_taggable_item_list)
and then I can use it in my view:
<%= f.text_field :more_taggable_item_list %>
I guess you have to use the plural form, as in the docs. So :items
instead of :item
and :more_taggable_items
instead of :more_taggable_item
. Rails offers a lot of functionality to use for gems when it comes to creating proper naming convetions and good gems make use of this.
# model
class Project < ActiveRecord::Base
acts_as_taggable_on :items, :more_taggable_items
end
# params
def project_params
params.require(:project).permit(
:user_id, :item_list, :more_taggable_item_list)
end
# view
<%= f.text_field :item_list %>
<%= f.text_field :more_taggable_item_list %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With