简体   繁体   中英

Render :partial with :layout don't work in view

so i have a problem with :partial rendering...

I have:

index.html.erb view with content of <%= render :partial => 'partial_test', :layout => 'partial_test' %> index.html.erb' layout with content of <%= yield %>`

_partial_test.html.erb view with content of simple string _partial_test.html.erb layout with content of <div id="_partial"><%= yield %></div>

After rendering i get proper content from controller (view + layout) index action, but from rendering partial i get only content from view, layout is missing.

I should get something like this: <div id="index"> <div id="_partial"> simple string </div> </div>

but i'm getting <div id="index"> simple string </div>

It's strange because when i render partial with layout from inside controller index action i get proper rendering of view + layout (only for partial).

Help needed :)

Instead of using

<%= render :partial => 'partial_test', :layout => 'partial_test' %>

what i needed to use was

<%= render :partial => 'partial_test', :layout => 'layouts/partial_test' %>

As I read the Rails docs, you don't want:

<%= render :partial => 'partial_test', :layout => 'partial_test' %>

You want:

<%= render 'partial_test', :layout => 'partial_test' %>

I'm not sure how/why your layout and partial have the same name, but please look at the Rails Guide at: http://guides.rubyonrails.org/layouts_and_rendering.html , Section 3.4.3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM