I''m reading Rails Recipes, for the precision the recipe 52 that speak about ''Making your own Rails plugin''. The question, so stupid, is that i don''t understand wath do the code def self.search(query, fields, options = {}) find :all, options.merge(:conditions => [[fields].flatten.map { |f| "LOWER(#{f}) LIKE :query"}.join('' OR '' ), {:query => "%#{query.to_s.downcase}%"}]) end I think that: - query: is the text i search - fields: are the fields of Post in witch i search - options: ? And then the command is a quite complicated for me, so i don''t understand what it do. Thanks so much to all. --Reis -- Posted via http://www.ruby-forum.com/.
Say you had a table, people, with fields: firstname, lastname, address, suburb, city, etc. Person.search ''Nic'', [:firstname, :lastname] will return results like: Person(:firstname => ''Nicholas'', :lastname => ''Williams'', ...) Person(:firstname => ''St. Nicholas'', :lastname => ''Claus'', ...) Person(:firstname => ''Reis'', :lastname => ''Supernice'', ...) options are the rest of the find options you might like to include, say: {:order => ''lastname, firstname asc''} Cheers Nic -- Posted via http://www.ruby-forum.com/.
Dr Nic wrote:> Say you had a table, people, with fields: firstname, lastname, address, > suburb, city, etc. > > Person.search ''Nic'', [:firstname, :lastname] > will return results like: > Person(:firstname => ''Nicholas'', :lastname => ''Williams'', ...) > Person(:firstname => ''St. Nicholas'', :lastname => ''Claus'', ...) > Person(:firstname => ''Reis'', :lastname => ''Supernice'', ...) > > options are the rest of the find options you might like to include, say: > {:order => ''lastname, firstname asc''} > > Cheers > NicThanks so much Dr Nic! --Reis -- Posted via http://www.ruby-forum.com/.