Thanks for providing a practical solution.  Having a little trouble
getting it to work, though.

It seems that the account_entity_id_form_column method isn't getting
called.  I put a line in there that logs a test message, and it's not
showing up in the output.

I have ActiveScaffold set up under an admin/ subdirectory, so the
controller is:
/app/controllers/admin/accounts_controller.rb

Just to be certain I got the location and naming right, I created two
helper modules, and pasted the method into both:
/app/helpers/accounts_helper.rb  (Module AccountsHelper)
/app/helpers/admin/accounts_helper.rb  (Module Admin::AccountsHelper)

Neither of them are being invoked.

BTW-Do I also need to add this?
> config.columns[:entity_id].form_ui = :select
Seems to make sense to me, since we're trying to make it a drop-down
box, but AS freaks out when do it.

Lastly, a theoretical question:  Why couldn't AS be modified to look
at the models that are associated with :account as entities?  Doesn't
Rails have both directions of the association available for
introspection?  Then AS could go and select all records in both tables
and include them in the drop-down box.  That's ultimately what I'd
prefer, and would be some awesome default logic to include.

-ofer

On Nov 12, 3:35 am, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Jueves, 11 de Noviembre de 2010 16:44:15 odigity escribió:
>
>
>
> > Kinda new here.
>
> > For this example, let's assume that I have three models:
>
> > Person
> >   has_many :accounts, :as => :entity
> > Organization
> >   has_many :accounts, :as => :entity
> > Account
> >   belongs_to :entity, :polymorphic => true
>
> > I can't create any accounts because ActiveScaffold won't display a
> > drop-down box on the create page with a list of people and
> > organizations, therefore I can't associate the account with an entity.
>
> > What's the best way to deal with this?
>
> ActiveScaffold can't guess what classes can act as entity.
> The best way is add a field for entity_type and another for entity_id.
> Set :select form_ui to entity_type, with Person and Organization as options.
> Then add a form override for entity_id:
>
> config.columns[:entity_type].form_ui = :select
> config.columns[:entity_type].options[:options] = ['Person', 'Organization']
> config.columns[:entity_type].update_column = :entity_id
>
> #AccountsHelper
> def account_entity_id_form_column(record, options)
>   select_options = if record.entity_type
>     record.entity_type.constantize.all.map {|r| [r.to_label, r.id]}
>   else
>     []
>   end
>   select :record, :entity_id, select_options, options
> 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