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