好的,所以当我提交表单时,这些是通过我的浏览器传递的参数:
{"Search"=>"Job Letter and CD #",
"utf8"=>"✓",
"search"=>"g",
"commit"=>"Search"}
基本上我需要做的是在我的模型测试中第一个参数“搜索”。前任:
if Search == "Job Letter and CD #"
..do stuff..
elsif Search == "something else"
..do different stuff..
else
..do something..
我一直在敲我的头,无法弄清楚。我的红宝石代码在下面,我可能会删掉一些“结束”之类的东西以节省空间。
index.html.erb
<form class="well form-search right">
<%= select_tag "Search", options_for_select([ "Job Letter and CD #", "Date", "Cust", "Job", "Date shipped", "Date billed", "Billed by" ], params[:search]) %>
<%= form_tag reports_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search], :class=> "form-search", :align => "right" %>
<%= submit_tag "Search", [ :JOBLETTER_CD_NUMBER, :DATE, :CUST, :JOB, :DATE_SHIPPED, :DATE_BILLED, :billed_by ] => nil, :class => "btn btn-success", :align => "right" %>
report.rb 模型
def self.search(search)
if Search == 'Job Letter and CD #'
where('JOBLETTER_CD_NUMBER LIKE ?', "%#{search}%")
elsif Search == 'Date'
where('DATE ?', "%#{search}%")
else
scoped
end
end