Module: FlexaLib::ActiveRecord::PesquisaWrapper
- Defined in:
- lib/flexa_lib/model_extensions.rb
Instance Method Summary collapse
-
#flexa_search(options) ⇒ Object
flexa_search BUSCA.
Instance Method Details
#flexa_search(options) ⇒ Object
flexa_search BUSCA
Model.flexa_search(:search => {:text => params[:search],
:fields => ['nome','cod_cidade']}, :page => params[:page])
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flexa_lib/model_extensions.rb', line 13 def flexa_search() = .dup = .fetch(:search) { raise ArgumentError, ":search is required" } likes_search = .fetch(:fields) { raise ArgumentError, ":fields is required" } text_search = .fetch(:text) { raise ArgumentError, ":text is required" } text_search ||= '' .delete(:search) if text_search.length > 0 and likes_search.count > 0 likes_search.collect! {|x| "(UPPER("+x+") LIKE UPPER(:search))"} paginate().where(likes_search.join(' OR '), :search => "%"+text_search.to_s+"%") else paginate() end end |