trabajo-afectivo/app/models/organization.rb

26 lines
615 B
Ruby
Raw Normal View History

class Organization < ApplicationModel
2012-04-10 14:06:46 +00:00
has_and_belongs_to_many :users
validates :name, :presence => true
2013-05-21 22:30:09 +00:00
def self.search(params)
# get params
query = params[:query]
limit = params[:limit] || 10
current_user = params[:current_user]
# enable search only for agents and admins
return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin')
# do query
organizations = Organization.find(
:all,
:limit => limit,
:conditions => ['name LIKE ?', "%#{query}%"],
:order => 'name'
)
return organizations
end
2012-04-10 14:06:46 +00:00
end