Displaying 2 results from an estimated 2 matches for "role_types".
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
...and associations look like this
class Movie < ActiveRecord::Base
has_many :roles, :include => :role_type, :dependent => :destroy
has_many :participants, :through => :roles, :source => :person do
def as(role_name)
self.scoped(
:joins => ''CROSS JOIN role_types'',
:conditions => [
"(roles.role_type_id = role_types.id) +
" AND role_types.name = ?",
role_name
]
)
end
end
...
end
Querying is easy:
m = Movie.find_by_title(''Gran Milano'')
m.participants.as(...
2009 Jul 02
1
Rails Select Helper
Dear All,
I m using the below select helper for my select helper which works fine.
<%=privilege. select :AC,Role.find(:all,:conditions => {:role_type =>
"AC"}).collect {|c| [ c.role_name, c.id ] },{},{:class => "txtbox"} %>
Its generates the below html...
<select name="privilege[AC]" id="privilege_AC" class="txtbox">