You first problem is that you have a name clash between the Rails class ActionView::Template
and your Template
model class. You can work around that by referring to your model class as ::Template
(a top-level Ruby class). e.g.
<% @template = ::Template.where("id = ?", @templatetask.template_id).first %>
But that is just a round about way of doing a primary key lookup which is simpler with find
:
<% @template = ::Template.find(@templatetask.template_id) %>
Even easier, if you have already set up a belongs_to
association from TemplateTask
to Template
you could just refer to the related object directly:
<% @template = @templatetask.template %>
That would probably get you a bit further but if you want to make your partials more reusable its might be better to avoid having them refer to instance variables (e.g. @template
). Instead the partial should refer to a local template
variable that you pass into the render
method via the locals
hash (which you are already doing).