views:

78

answers:

1

If I have a model (Choice) belonging to a polymorphic association (Suggestion), is it possible to create the associated Suggestion in a form for the Choice?

Essentially, what I'm trying to do is allow a user to create a "Choice" in a poll, with potential suggestions being predefined Venues, Cities, or Districts, but also to allow an option for custom free-form suggestion (just text, and not a predefined entity existing in my database). For Venues/Cities/Districts, it's simple enough to just give the user a selection option and associate the Choice with it, but is it possible for a CustomSuggestion to create it on the fly and associate the Choice with it?

I was thinking that what I really want is the association to be has_one CustomSuggestion, to allow for association building, but then that would be a different association from the belongs_to :suggestion, :polymorphic => true.

Any ideas?

Thanks, Eric

A: 

I have done this in the past and I didn't bother with a complex object model for it. For example, in a job application form, I had a "how did you hear of us question?" If you filled in the box, I took that as a filled in answer. So, I had a "belongs_to" that pointed to the normal choices, but just a text field on the model for a custom one.

Your suggestions table is going to look weird when there are multiple people with the same suggestion. In general, I question when something is modeled as a "has_one".

MattMcKnight