0

Hi I have a search bar for my Firms.. however it seems to be throwing up and error and I cannot work out why!

My View

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 %>

My firms_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

This used to work fine, but now it is tossing up this error.

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'

Any ideas? Thanks in advance for any help

Ross

4

1 回答 1

1

Modify

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
于 2012-04-13T12:37:21.933 回答