I'm using Rails 3, mac os mountain lion and Ruby 1.9.3
So i have this object called object1. I built a search function for it and it works properly:
def self.search(search)
search_condition = "%" + search + "%"
if search
find(:all, :conditions => ['name LIKE ?', search_condition])
else
find(:all)
end
end
Now I want to use this in object2. So in object2 controller I wrote:
def search
@results = Object1.search(params[:search])
end
and in the view:
= form_tag object2_path, :method => 'get' do
#{text_field_tag :search, params[:search], :id => 'search_field'}
#{submit_tag "Search", :name => nil}
- for result in @results
%li
= result.name
But for some reason the @results return nil. What's wrong with what I'm doing? Thanks a lot.