Rails STI and view reuse
I have an STI model and would like to reuse the underlying views for a derived model. For example, if I have a Teacher, I would like the Teacher view to contain the person's fields of vision.
Is there a way to achieve this?
If I understand your question ... they are available by default. When using STI, each derived model has access to all fields of the base class. (any field in the table)
For example, with a partial view, you can simply pass the object as usual:
= render :partial => 'person', :object => @teacher
The code above can be done in several ways, but I'm just trying to illustrate.
If you have teachers and people controllers, you can render views (partials, templates) from faces inside teachers views.
<strong> Examples
You can write below line inside teacher views
= render :partial => 'persons/<PARTIAL NAME>'
= render :template => 'persons/<TEMPLATE>'
= render :file => 'persons/new'
render
use the right partial, so if you have partial parts _teacher.html.erb
and _person.html.erb
, you can render
person, the part is inside the teacher, and when you call render
with an object, then the right part will turn out to be:
# @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
Since the teacher partially reflects the person, you have information in this case.