Reputation: 336
For example:
I'm have two models: Task
and List
. Task
belongs_to
List
.
I'm render lists/_form.html.erb
partial within lists/show.html.erb view
.
Now I need to render tasks/_fields.html.erb
partial within lists/_form.html.erb
partial:
<%= render 'tasks/fields' %>
But I get an error ActionView::MissingTemplate
If I try to render tasks/_fields.html.erb
within lists/_form.html.erb
, everything works.
I see two bad ways to solve this problem:
_fields.html.erb
to lists
folderlists/_form.html.erb
partial and try a "Nested Layouts" from http://guides.rubyonrails.org/layouts_and_rendering.htmlIs there a good way?
Upvotes: 30
Views: 29158
Reputation: 1389
Based on @ArunKumarArjun but with the new Rails notation:
<%= render partial: 'tasks/fields' %>
Upvotes: 5
Reputation: 8568
For Rails 5 & above:
You better use the render without partial like this:
<% render 'tasks/fields' %>
Because the partial
can cause this kind of issues & is not needed any more
Upvotes: 7
Reputation: 10413
If you are sharing things like this, why not put them into a folder like app/views/shared/
or directly into app/views/layouts
?
Upvotes: 6