Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 683
xyz Avatar asked Apr 03 '11 19:04

xyz


People also ask

How can you tell Rails to render without a layout?

2.2. By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.

How should you use nested layouts in Rails?

The layouts removes code duplication in view layer. You are able to slice all your application pages to blocks such as header, footer, sidebar, body and etc. This is an example of typical web application page, almost every site has these blocks. And as a rule the body block differs on each page.

What is Local_assigns?

local_assigns is a Rails view helper method that you can check whether this partial has been provided with local variables or not. Here you render a partial with some values, the headline and person will become accessible with predefined value.

What keyword is used in a layout to identify a section where content from the view should be inserted?

Within the context of a layout, <%= yield %> identifies a section where content from the view template should be inserted. The simplest way to use this is to have a single yield, into which the entire contents of the view currently being rendered is inserted.


1 Answers

Instead of using

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

what i needed to use was

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

like image 190
xyz Avatar answered Sep 24 '22 12:09

xyz