Basic Ruby On Rails Linking Help
- by dweebsonduty
So I am beginning to work with Rails and I get some of the concepts but am stuck on an important one.
Let's say I have customers which has many jobs and jobs which belongs to customers.
How would I go about creating a new job for a customer?
I can create a link that goes to customers/1/jobs/new and I can grab the customer ID but how do I tell it that I am creating a job for customer 1?
I know this is the most basic of things but I just need a push in the right direction.
This is my form so far:
How do I get :customer_id to populate with the customer_id param?
<h1>New job</h1>
<% form_for(@job) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :customer_id %><br />
<%= f.text_field :customer_id %>
</p>
<p>
<%= f.label :manufacturer %><br />
<%= f.text_field :manufacturer %>
</p>
<p>
<%= f.label :serial_number %><br />
<%= f.text_field :serial_number %>
</p>
<p>
<%= f.label :problem %><br />
<%= f.text_area :problem %>
</p>
<p>
<%= f.label :notes %><br />
<%= f.text_area :notes %>
</p>
<p>
<%= f.label :status %><br />
<%= f.text_field :status %>
</p>
<p>
<%= f.label :tech_id %><br />
<%= f.text_field :tech_id %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', jobs_path %>