secret
Last active

  • Download Gist
bracket.rb
Ruby
1 2 3 4 5 6 7
class Bracket < ActiveRecord::Base
has_one :ownership, :as => :app
has_one :owner, :through => :ownership, :source => :user
 
has_many :memberships, :as => :app, :conditions => "status = '#{Membership::Status::MEMBER}' OR type = 'Ownership'"
has_many :members, :through => :memberships, :source => :user
end
controller.rb
Ruby
1 2 3 4
def index
@search = @klass.search(params[:search])
@records = @search.paginate :per_page => params[:per_page] || 20, :page => params[:page] || 1
end
form.haml
Haml
1 2 3 4 5
- form_for @search, :html => {:id => 'bracket_search_form' }do |f|
= hidden_field_tag :format, 'admin'
 
= f.label :owner_email_like, 'Owner Email:'
= f.text_field :owner_email_like
membership.rb
Ruby
1 2 3 4
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :app, :polymorphic => true
end
ownership.rb
Ruby
1 2 3
class Ownership < Membership
 
end
query.sql
SQL
1 2 3 4
SELECT `brackets`.* FROM `brackets`
INNER JOIN `memberships` ON (`brackets`.`id` = `memberships`.`app_id` AND `memberships`.`app_type` = 'Bracket')
INNER JOIN `users` ON (`users`.`id` = `memberships`.`user_id`)
WHERE (users.email LIKE '%dj%') LIMIT 0, 20

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.