I'm creating a join table that will show me which employee sold which comic. When I type in my employee name It is giving me this error
NoMethodError in Showemployeesales#employeesaleout
undefined method `name_id' for nil:NilClass
Here is my code for my controller
def employeesaleout
@employee_name = params[:employee_name_in]
r = Employee.find_by_name_id(@employee_name)
@sale_list = r.sales
end
Here is my code for my input view "employeenamein"
<h1>Showemployeesales#employeenamein</h1>
<p>Find me in app/views/showemployeesales/employeenamein.html.erb</p>
<%= form_tag(showemployeesales_employeesaleout_path, :controller =>
"showemployeesales", :action => "employeesaleout", :method => "post") do
%>
<div class="field">
<%= label_tag :Employee_Name %><br />
<%= text_field_tag :employee_name_in %>
</div>
<div class="actions">
<%= submit_tag "Submit Employee Name" %>
</div>
<% end %>
Here is my code for my output view
<center><h1>These are the Sales for <%= @employee_name %> </h1></center>
<br /> <br />
<center><table width = 65% border = 1>
<tr> <th> Comic Name </th><th> Comic ID </th></tr>
<% @sale_list.each do |m| %>
<tr> <td> <%= m.product.name_id %> </td> <td> <%= m.product.id_no %>
</td></tr>
<% end %> </table> </center><br /> <br />
And my products table under my schema
create_table "products", force: :cascade do |t|
t.string "name_id"
t.integer "id_no"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire