7

I'm trying to create a drop-down select box for a polymorphic association with ActiveScaffold.

I have:

class Award
  belongs_to :sponsorship, :polymorphic => :true
end

class Organization
  has_many :awards, :as => :sponsorship
end

class Individual
  has_many :awards, :as => :sponsorship
end

While trying to create a select drop-down box in awards_controller with:

config.columns[:sponsorship].form_ui = :select

I get the following error:

ActionView::TemplateError (uninitialized constant Award::Sponsorship)

I'm not sure if it's something I'm not doing right or what I'm trying to accomplish not directly supported in AS.

Would really appreciate some advice.

Swartz
  • 71
  • 2

3 Answers3

0

I'm not familiar with ActiveScaffold... But, a quick pass in their documentation revealed a section about has_many :through which I am familiar with from ActiveRecords... so for what it's worth, is it possible that your polymorphic associations should be written like this?:

class Organization
  has_many :awards, :through => :sponsorship
end

class Individual
  has_many :awards, :through => :sponsorship
end
Hugo
  • 2,913
  • 1
  • 20
  • 21
0

I'm not sure of what you're trying to do, but rails is indeed true when saying that there is no ":sponsorship'.

When polymorphism is used, rails automatically create two columns, in your case : *sponsorship_id* and *sponsorship_type*.

You may want to use one of those.

However, I'm not familiar with ActiveScaffold form_ui, so I cannot help you further.

Offirmo
  • 18,962
  • 12
  • 76
  • 97
0

I am getting this error, but only if I have an instance of Award with no sponsorship (my names are different...). So presumably the OP and follow up posters got past this, but for future readers, make sure you don't create an instance of the dependent model when using a polymorphic association with active_scaffold...

nroose
  • 1,689
  • 2
  • 21
  • 28