On Martes, 27 de Abril de 2010 20:43:52 petehern escribió:
> I'm making an app that tracks registered voters and canvassing
> (knocking on doors). The models look like:
>
> class Voter < ActiveRecord::Base
>   belongs_to :house
>   has_many :canvass_voters
> end
>
> class House < ActiveRecord::Base
>   has_many :voters
>   has_many :canvasses
>   has_many :canvass_voters, :through => :canvasses
> end
>
> class Canvass < ActiveRecord::Base
>   belongs_to :house
>   has_many :canvass_voters
> end
>
> class CanvassVoter < ActiveRecord::Base
>   belongs_to :canvass
>   belongs_to :voter
> end
>
> The CanvassVoter record is necessary because we may talk to more than
> one voter when we knock on a door.
>
> Here's my problem: when I add a Canvass to a House (ie browsing the
> Houses, click the Canvass column, click "Create New"), the subform for
> associating a CanvassVoter is a pull-down list of all voters
> (thousands!), but I only want it to be a pull-down list of those
> voters registered at that house. I've been trying to do this a subform
> override, but I don't know how to reference the house_id from the
> subform.

You have to override options_for_association_conditions in your 
CanvassesHelper, and you can get the house_id with 
active_scaffold_constraints[:house]:

def options_for_association_conditions(association)
        if association.name == :canvass_voter
                ["#{association.primary_key_name} IS NULL AND house_id = ?", 
active_scaffold_constraints[:house]]
        else
                super
        end
end
-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.

Reply via email to