Format selection list

<% semantic_form_for(@product, :html => {:multipart => true}) do |f| %> <% f.inputs do %> <%= f.input :name %> <%= f.input :price %> <%= f.input :pno %> <%= f.input :description %> <%= f.input :shop_category %> <% end %> <% end %> 

Product belongs to Shop_category, Shop_category belongs to the Store.

How to change the line:

 <%= f.input :shop_category %> 

Show only shop_categories categories belonging to a store with an identifier, for example 15 instead of showing all shop_categories categories in the selection box?

+4
source share
2 answers

There is an option :collection to enter the selection.

 <%= form.input :shop_category, :collection => @shop.ShopCategories %> 

Thus, you can provide the Hash attribute for this collection to display the categories that you need, with the required conditions.

+13
source

In addition, if you set shop_category in the controller, it will be selected as the default value.

+1
source

All Articles