2014-04-17 51 views
1

我有一個簡單的嵌套窗體,它顯示用戶的儀表板的字段以及儀表板的tile(aka窗口小部件)的嵌套屬性。我正在使用Rails 4.1,並且只想爲enum :middle_column (whose value is 2)顯示:tiles。將f.simple_fields_for :tiles do |builder|更改爲enum :middle_column的適當語法是什麼?Rails 4.1 enum限制返回fields_for

<%= simple_form_for [@user, @dashboard] do |f| %> 
    <%= f.simple_fields_for :tiles do |builder| %> 
    <%= render "widgets/#{builder.object.widget.function}_fields", f: builder %> 
    <% end %> 
<% end %> 

回答

1

傻了我。我可以將第二個參數傳遞給simple_fields_for,這會限制結果。

f.simple_fields_for :tiles, f.object.tiles.where(position: Tile.positions[:middle_column]) do |builder|