I have an STI model and would like to reuse the base views for the derived model. For example, If I have Teacher < Person I would like the Teacher's view to contain the person's view fields.
Is there a way to achieve this?
I have an STI model and would like to reuse the base views for the derived model. For example, If I have Teacher < Person I would like the Teacher's view to contain the person's view fields.
Is there a way to achieve this?
If I'm understanding your question...they're available by default. When using STI each derived model has access to all the fields from the base class. (any field on the table)
For example, when rendering a partial, you could simply pass the object as normal:
= render :partial => 'person', :object => @teacher
The code above can be done in several ways, but I'm just trying to illustrate.
If you are having teachers and persons controller then you can render views(partials, templates) from persons inside teachers views.
Examples
You can write below lines inside teachers views
= render :partial => 'persons/<PARTIAL NAME>'
= render :template => 'persons/<TEMPLATE>'
= render :file => 'persons/new'
render
use the right partial so if you have the _teacher.html.erb
and _person.html.erb
partials you can render
the person partial inside the teacher one and when you call render
with an object the right partial will be rendered:
# @aldo is a Person, this will render _person.html.erb
render @aldo
# @mr_brown si a Teacher, this will render _teacher.html.erb
render @mr_brown
Because the teacher partial render the person one you have in that case both the information.