title: Fields for selected value
body: <p>I have a form that has a fields for helper in it and I need to get the value of each of those fields in my rails application. </p>
  
  <pre><code>&lt;%= form.fields_for :expenses do |expense| %&gt;
        &lt;%= render 'expense_fields', f: expense %&gt;
  &lt;% end %&gt;
  &lt;%= link_to_add_fields "Add field", form, :expenses %&gt;
  </code></pre>
  
  <p><strong>expense_fields.html.erb</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="col-md-5"&gt;
      &lt;div class="form-group"&gt;
          &lt;%= f.label :expense_name %&gt;
          &lt;%= f.select(:expense_name, options_for_select([['Hotel', 'hotel'], 
          ['Registration', 'registration'], 
          ['Meals', 'meals'], 
          ['Flight', 'flight'], 
          ['Mileage', 'mileage'],
          ['Car Rental', 'car rental'],
          ['Parking', 'parking'],
          ['Traning', 'training']],), { include_blank: true }, id: 'principal_selection', class: 'form-control') %&gt; 
      &lt;/div&gt;
    &lt;/div&gt;
      &lt;% if current_user.admin? || current_user.principal? || current_user.super? %&gt;
        &lt;div class="col-md-3"&gt;
      &lt;% else %&gt;
        &lt;div class="col-md-7"&gt;
      &lt;% end %&gt;
        &lt;div class="form-group"&gt;
          &lt;%= f.label :expense_cost %&gt;
          &lt;%= f.number_field :cost, class: 'form-control', placeholder: 'Cost', step: :any %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;% if current_user.principal? || current_user.admin? || current_user.super? %&gt;
    &lt;div class="col-md-4"&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :payment_type %&gt;
        &lt;%= f.select(:payment_type, options_for_select([['Out of pocket', 'Out of Pocket'], ['Corporate Card', 'Corporate Card'], ['PO', 'PO']], selected: "Half Day"), { include_blank: false }, class: 'form-control') %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have checked around the rails guides and was not able to find a way to directly extract the value for each fields for in the select helper. Anybody have any ideas?</p>
  
  <p>I tried doing <code>selected: "#{@expense.expense_name}"</code> but get a nil error because @expense is not defined. So I went into the edit method in the pdforms controller and tried this:</p>
  
  <pre><code>def edit
  @expenses = @pdform.expenses
  end
  </code></pre>
  
  <p>That yielded no result so I tried this:</p>
  
  <pre><code>def edit
  @expenses = @pdform.expenses
  @expenses.each do |ex| 
    @expense = ex
  end
  </code></pre>
  
  <p>But that just returned one value in the form when it is being edited. Any other ideas? </p>