select-many needs the list of items if you want it to reduce the
available list. instead of doing the has_many again, do a named_scope
like this maybe:
named_scope :devices_by_contract, lambda { { :conditions =>
['contract_id = ?', contract_id } }
changed contract.id to contract_id to avoid potential extract db
call. had to do lambda (I think) because it needs to be evaluated in
the context of whatever the current record is.
On Feb 12, 10:10 am, Grzegorz Marszałek <[email protected]> wrote:
> Hello!
>
> I'm trying to figure out, how to limit choices using select-many tag.
> Code is like this:
>
> class Contract < ActiveRecord::Base
> ...
> has_many :devices
> has_many :networks
> has_many :groups
> ...
> end
>
> class Device < ActiveRecord::Base
> ...
> belongs_to :contract
> has_many :group_memberships
> has_many :groups, :through => :group_memberships, :accessible => true
> ...
> end
> class GroupMembership < ActiveRecord::Base
> ...
> belongs_to :group
> belongs_to :device
> ...
> end
> class Group < ActiveRecord::Base
> ...
> belongs_to :contract
> has_many :group_memberships
> has_many :devices, :through => :group_memberships, :accessible =>
> true
> end
>
> and in application.dryml:
> <extend tag="form" for="Group">
> <old-form merge>
> <field-list: fields="name, devices"/>
> </old-form>
> </extend>
>
> Now - it's working fine, but each time I edit Group I get select field
> with ALL devices. My goal is to limit this list to devices belonging
> to THE SAME contarct, as group. I've try something like this in Group
> class:
>
> has_many :devices, :through => :group_memberships, :accessible =>
> true, :conditions => ['contract_id = ?', self.contract.id]
>
> But it doesn't work as I though it would :(
>
> Any ideas or clues? :)
> ---
> Grzegorz Marsza³ek
> [email protected]
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.