I have a simple nested form where it displays the fields for a user's dashboard and the nested attributes for the dashboard's tiles (aka widgets). I'm using Rails 4.1 and would like to only display the :tiles for the enum :middle_column (whose value is 2). What would be the proper syntax for changing the f.simple_fields_for :tiles do |builder| to limit to the enum :middle_column?

<%= 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 %>
有帮助吗?

解决方案

Silly me. I can pass a second argument to the simple_fields_for which will limit the results.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top