Ruby on rails 简单RubyonRails控制器错误消息?
在我的网站上,我试图输入员工的姓氏,以便显示员工销售的相应手机。所以在终端我输入了这个Ruby on rails 简单RubyonRails控制器错误消息?,ruby-on-rails,Ruby On Rails,在我的网站上,我试图输入员工的姓氏,以便显示员工销售的相应手机。所以在终端我输入了这个 rails g controller showemployeesales employeenamein salesout 我编辑了控制器、route.rb、输入和输出文件。以下是这些部分的代码: 控制器:` class ShowemployeesalesController < ApplicationController def employeenamein
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
类ShowemployeesalesController
输入文件:
<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 %>
请输入要为其显示的员工的姓名
出售
“salesout”,方法=>“post”)
输出文件:
<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
“未定义的方法”按“最后一次”查找“你的意思是什么?
通过\ sql查找\ U
当我导航到我的“/showemployeesales/employeenamein”时
我收到一个错误,上面写着:
/home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3:语法错误,意外的tSTRING\u BEG,应为“)”…es\u salesout\u路径,:controller“showemployeesales”,:action=…^/home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3:语法错误,意外“,”,预期“)”…控制器“showemployeesales”,:action=>“salesout”,:meth…^/home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:3:语法错误,意外“,”预期“,”esales“,:action=>“salesout”,:method=>“post”)…^/home/ubuntu/workspace/app/views/showemployeesales/employeenamein.html.erb:5:语法错误,意外“查询记录,如:Model.where(电邮:’example@domain.com').last
find_by
仅返回一个实例,无法将last
应用于itI我不确定您得到了什么。我对Ruby on Rails相当陌生。我最初使用的是模型。find_by
返回单个记录,因此无法使用。last
适用于集合/数组。