Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1

Search for Site in rails


I am trying to create a form where I can retrieve the information. So far I have implemented a model and a controller with an action query.

Here's the form:

<%= form_tag "/search", :method => "get" do %>
  <%= text_field_tag :query, params[:query] %>
  <%= submit_tag "Search", :name => nil %>
<% end %>

My controller has:

def query @results = Search.search(params[:query] ) end

And in my models I have:

def self.search(search)
  if search
    Customer.find(:all, :conditions => ['first LIKE ?', "%#{search}%"])
  else
    Customer.find(:all)
  end
end

But it give me the following error:

ActiveRecord::StatementInvalid in SearchesController#query

SQLite3::SQLException: no such column: first: SELECT "customers".* FROM "customers"  WHERE (first LIKE '%test%')

Why does my code produce this error?


Solution

  • That's probably because you don't have a first column in customers table on the DB.

    Did you mean maybe first_name ?