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.html Is there a good way?
Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html.
Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
A partial allows you to separate layout code out into a file which will be reused throughout the layout and/or multiple other layouts. For example, you might have a login form that you want to display on 10 different pages on your site.
Try this:
<%= render :partial => 'tasks/fields' %>
If you are sharing things like this, why not put them into a folder like app/views/shared/
or directly into app/views/layouts
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With