Tuesday, December 28, 2010

search method rails


The controller ( users_controller.rb)
def index
 
@users = User.search(params[:search])
end
and the method in user model:
def self.search(search)
  search
.present? and all(:conditions => [ 'name LIKE ?', "%#{search.strip}%" ])
end

No comments:

Post a Comment