acts as taggable on - (Rails 4, acts_as_taggable_on): Using dynamic context in controller -
acts_as_taggable_on great , easy work when using static contexts. i'm trying store tags selected user in context depends on 1 of model's attributes.
the model ingredient
, has attribute center_id
. i'd user able select tags , context string based on center_id
.
i need getting right code controller , view.
model:
class ingredient < activerecord::base belongs_to :center
helper:
module ingredientshelper def get_all_tags_for_center return ingredient.tags_on(get_tags_context) end def get_tags_context "c#{@ingredient.center_id}_ingredient" end end
view - tried this, may not right thing dynamic contexts:
<%= f.association :tag_list %> <%= f.select :tag_list, options_for_select(get_tags, @ingredient.tag_list_on(get_tags_context)), {}, {class: 'doselect2', multiple: true } %> <% end %>
controller - needed.
solved. future readers:
controller:
@ingredient.set_tag_list_on get_tags_context, params[:tags].join(",") if @ingredient.update_attributes(ingredient_params) . . end
view:
<%= select_tag "tags[]", options_for_select(get_tags, @ingredient.tag_list_on(get_tags_context)), class: 'doselect2', multiple: true %>
Comments
Post a Comment