您好我的公司有一个搜索栏..但它似乎是呕吐和错误,我无法理解为什么!
我的观点
application.html.erb
<%= form_tag firms_path, :method => 'get', :class => 'form-search' do %>
<%= text_field_tag :search, params[:search], :class => 'input-medium search-query', :placeholder => 'Firm name' %>
<%= submit_tag "Search", :name => nil ,:class => 'btn' %>
<% end %>
我的firm_controller.rb
def index
@firms = Firm.search(params[:search])
end
def self.search(search)
if search
where(['name LIKE ?', "%#{search}%"]).page(params[:id])
else
scoped
end
end
这曾经工作得很好,但现在它正在抛弃这个错误。
NameError in FirmsController#index
undefined local variable or method `params' for #<Class:0x007f93cd8b2ac8>
app/models/firm.rb:13:in `search'
app/controllers/firms_controller.rb:8:in `index'
有什么想法吗? 在此先感谢您的任何帮助
罗斯
答案 0 :(得分:1)
修改
def index
@firms = Firm.search(params[:search], params[:id])
end
def self.search(search, id)
if search
where(['name LIKE ?', "%#{search}%"]).page(id)
else
scoped
end
end