0

I'm trying to build a model which render/process partials from others models. Basically, a master model would provide some generic features while embedding different models depending on user input.

In other words, within the same model, I need to render "_form.html.erb" from various models and save them as a nested model would do.

I know nested model would do the work if it was always the same type of model.

class Master < ActiveRecord::Base
  has_one :{change depending on user input}
  accepts_nested_attributes_for :{change depending on user input}
end

I seen polymorphic models but it seems to do the exact opposite (i.e. one partial in multiple models).

Any ideas? Polymorphic nested model or something?

1 Answer 1

1

It definitely looks like you need a polymorphic association here, but accepts_nested_attributes_for does not support polymorphism.

However, take a look at this related question accepts_nested_attributes_for with belongs_to polymorphic

Maybe in your form you could do something like the following to render the correct _form partial:

<%= render :partial => File.join(@master.thing.class.name.underscore.pluralize, "form") %>

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.