Dave
Dave

Reputation: 666

Rails erb alterantive to fields_for find specific record

I'm new to rails, and trying to modify an existing application.

I have a model that has a 'has_many' relationship with another type of record 'group_parameters'. Group parameters has two fields (name and value).

I currently have a form that scopes group_parameters and prints all the stored records. This is achieved by doing

<%= f.fields_for group_parameters do | builder | %> Attribute <%= builder.text_field(:name) %> <% end %>

Instead I'd like to only display certain records where the name field equals a specific string. Is there a simple method to help with this?

Upvotes: 1

Views: 158

Answers (1)

Jagdish Narayandasani
Jagdish Narayandasani

Reputation: 772

<%= f.fields_for group_parameters, @specific_records do | builder | %> 
    Attribute <%=   builder.text_field(:name) %>
<% end %>

Fetch data from DB as per your criteria and assign to @specific_records

Upvotes: 3

Related Questions