Simple search only searching last word of record
Posted
by
bennett_an
on Stack Overflow
See other posts from Stack Overflow
or by bennett_an
Published on 2011-11-22T17:42:17Z
Indexed on
2011/11/22
17:51 UTC
Read the original article
Hit count: 152
ruby-on-rails
|search
I set up a simple search as instructed in part of railscast #240.
in controller
@reports = Report.search(params[:search]).order('created_at DESC').paginate(:page => params[:page], :per_page => 5)
in model
def self.search(search)
if search
where('apparatus LIKE ?', "%#{search}")
else
scoped
end
end
in view
<%= form_tag reports_path, :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
it all works... but...
I have a few records for example, one with "another time test" and another with "last test of time"
if i search "test" the first comes up but the second doesn't, and if i search "time" the second comes up but not the first. It is only seeing the last word of the record.
what gives?
© Stack Overflow or respective owner