开发者

How do i go about searching in Ruby on Rails?

开发者 https://www.devze.com 2023-01-05 13:05 出处:网络
I would like to implement a simple search. Let\'s say the user enters \'york\', then I would like to find all records that has a matching substrin开发者_StackOverflow社区g like \'new york\' or \'yorks

I would like to implement a simple search. Let's say the user enters 'york', then I would like to find all records that has a matching substrin开发者_StackOverflow社区g like 'new york' or 'yorkshire'.

So far I have figured out I will have to use the find method, but I can't figure out how to match for substrings.


city = params[:q]
User.find(:all, :conditions=>["city like :text", {:text=>"%#{city}%"} ] )


You might want to take a look at the Thinking Sphinx plugin for doing such full text search . Solr is also another option .

0

精彩评论

暂无评论...
验证码 换一张
取 消