title: Ruby on Rails: One to many relationship view
body: <p>New to rails and trying to get a one to many relationship up and running. I have it working in the Model and Controller, but I'm having trouble getting it up and running in the views.</p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
    has_many :non_labor_expenses
  end
  
  class NonLaborExpense &lt; ActiveRecord::Base
    belongs_to :project
  end
  </code></pre>
  
  <p>I manually created some entries in the the non_labor_expense table by loading the @non_labor_expenses in the controller (edit action) and can pull the existing data in the project view like so:</p>
  
  <pre><code>&lt;% unless @non_labor_expenses.nil? %&gt;
    &lt;% count = 1 %&gt;
    &lt;% for expense in @non_labor_expenses %&gt;
      &lt;li&gt;
        &lt;div class="label"&gt;&lt;%= f.label :expense , "Expense" + count.to_s %&gt;&lt;/div&gt;
        &lt;%= '$' + expense.amount.to_s + ' - ' + expense.description.to_s %&gt;
  
      &lt;/li&gt;
    &lt;% count = count +1 %&gt;
    &lt;% end %&gt;
  </code></pre>
  
     
  
  <p>What I am having trouble doing is adding a new non_labor_expense entry to the project. I should be able to manage handling it on the backend, but I can't even get the field to show up in the form.</p>
  
  <p>Here's where I'm at now:</p>
  
  <pre><code>&lt;li class="editable"&gt;
    &lt;div class="label"&gt;&lt;%= f.label :non_labor_expenses %&gt;&lt;/div&gt;
    &lt;%= f.text_field :non_labor_expenses %&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>I know my above code looks nothing like this, but ideally the form fields would be something like:</p>
  
  <pre><code>Expense Amount [text input]
  Expense Description [text input]
  </code></pre>
  
  <p>My full form code can be found here: <a href="http://pastebin.com/m2b280b0f" rel="nofollow noreferrer">http://pastebin.com/m2b280b0f</a> </p>