好的,我是这个网站的新手,但这就是我所拥有的:
报告.rb
def self.search(search)
if search
where('JOBLETTER_CD_NUMBER LIKE ? AND DATE LIKE? AND CUST LIKE ?', "%#{search}%")
else
scoped
end
end
end
index.html.erb
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 => nil, :class => "btn btn-success", :align => "right"
报告控制器
def index
@report = Report.paginate(:per_page => 1, :page => params[:page])
@report = Report.search(params[:search]).paginate(:per_page => 1, :page => params[:page])
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @views }
end
end
它将搜索的唯一字段是 Job Letter 和 CD # 字段,我需要它来搜索下拉框中选择的任何内容。顺便说一句,我正在使用 js 和 css 函数的引导程序。