开发者

Formtastic select 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 Shop.

How to change the line :

<%= f.input :shop_category %>

To show only shop_categories that belongs to Shop with id for example 15 instead of showing all shop_categories in the sel开发者_StackOverflow社区ect box ?


There's a :collection option for the select input.

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

So you can, by providing a Hash to that collection attribute, display the categories you need, with the required conditions.


Also, if you set the shop_category in the controller, it will already be selected as a default value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜