在我的网站上,我正在尝试输入员工的姓氏,以便向我显示员工已售出的相应手机。所以在终端我输入了
rails g controller showemployeesales employeenamein salesout
我编辑了我的控制器,route.rb,输入和输出文件。这是我的代码:
控制器:`
class ShowemployeesalesController < ApplicationController
def employeenamein
end
def salesout
@employee_name = params[:employee_name_in]
@r = Employee.find_by_last(@employee_name)
@sale_list = @r ? @r.sales : nil
@sale_list = Sale.all
end
end
输入文件:
<h2>Please enter the name of the Employee for whom you want to show
sales</h2>
<%= form_tag(showemployeesales_salesout_path, :controller
"showemployeesales", :action => "salesout", :method => "post")
<div class="field">
<%= label_tag :Employee_Name %><br />
<%= text_field_tag :employee_name_in %>
</div>
<div class="action">
<%= submit_tag "Submit Employee Name" %>
</div>
<% end %>
输出文件:
<center><h1>These are the sales for <%= @employee_name %></h1></center>
<center><table width = 65% border = 1>
<tr> <th> Phone Name </th><th> Phone ID Number </th>
<% @sale_list.each do |m| %>
<tr> <td> <%= m.mobile %> </td> <td> <%= m.employee %></td></tr>
<% end %> </table> </center>
运行我的网站后,我收到一条错误消息:
`undefined method `find_by_last' for #<Class:0x007f9d1e963170> Did you mean?
find_by_sql
当我导航到我的&#34; / showemployeesales / employeenamein&#34;
我收到错误消息:/home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3: syntax error, unexpected tSTRING_BEG, expecting ')' ...es_salesout_path, :controller "showemployeesales", :action =... ... ^ /home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3: syntax error, unexpected ',', expecting ')' ...controller "showemployeesales", :action => "salesout", :meth... ... ^ /home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3: syntax error, unexpected ',', expecting ')' ...esales", :action => "salesout", :method => "post") ... ^ /home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:5: syntax error, unexpected '<', expecting keyword_end <div class="field"> ^ /home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:6: syntax error, unexpected '<' <%= label_tag :Employee_Name );@output_buffer.safe_append='<br /> ^ /home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:15: syntax error, unexpected keyword_ensure, expecting end-of-input
并突出显示此行<%= form_tag(showemployeesales_salesout_path, :controller "showemployeesales", :action => "salesout", :method => "post")
答案 0 :(得分:1)
查询记录,如:git diff