Basically I have 2 tables called Employees and Sales. I have a form where you input the Employee name and it should show you what phones they have sold. Every time I input the name I get this error
undefined method `sales' for #<Employee:0x007f013e23fdc0>
And it highlights the @sale_list = r.sales part of the code shown below (my controller)
class ShowEmployeeSalesController < ApplicationController
def employeesaleout
@employee_name = params[:employee_name_in]
r = Employee.find_by_name_id(@employee_name)
@sale_list = r.sales
end
end
This is my code for the input view:
<h2>
Please enter the name of the Employee for whom you want to see the sales
</h2>
<%= form_tag(show_employee_sales_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 %>
This is my code for output view:
<h1>ShowEmployeeSales#employeesaleout</h1>
<center>
<h1>
These are the Sales for <%= @employee_name %>
</h1>
</center><br /> <br />
<center>
<table width = 65% border = 1>
<tr>
<th> Phone Name </th>
<th> Phone ID </th>
</tr>
<% @sale_list.each do |m| %>
<tr>
<td>
<%= m.Mobile %>
</td>
<td>
<%= m.Employee %>
</td>
</tr>
<% end %>
</table>
</center><br /> <br />
All of my tables have data in them.
Aucun commentaire:
Enregistrer un commentaire