Conditional Rails sidebar in application layout

Below is my application layout file

  .container_12.clearfix
  = render :partial => 'shared/flashes'

  .grid_8
    = render :partial => 'shared/search'        
    = yield
  .grid_4
    = yield(:sidebar)

It has grids, one for content and one for the sidebar. Now I am creating a login page in which I do not want to show my sidebar (only one grid. I can just create a new layout with div.grid_12 div as the only grid.

But that leaves me with two application mockups. How can I make the same application template conditional to get a sidebar?

If with the sidebar it will be the same as above, otherwise just one .grid_12, like the one below

  .container_12.clearfix
  = render :partial => 'shared/flashes'      
  .grid_12
    = render :partial => 'shared/search'        
    = yield
+5
source share
2 answers

, :sidebar , . Rails 2.3.5 content_for?. Helperful Gem.

- if has_content?(:sidebar)
  .grid_8
    = render :partial => 'shared/search'        
    = yield
  .grid_4
    = yield(:sidebar)
- else
  .grid_12
  = render :partial => 'shared/search'        
  = yield

, : sidebar == false, .

  def sidebar(enable = true, &block)
    if enable
      content_for :sidebar, &block
    else
      @fullpage = true
    end
  end

  def fullpage?
    !!@fullpage
  end

- if fullpage?
  .grid_12
  = render :partial => 'shared/search'        
  = yield
- else
  .grid_8
    = render :partial => 'shared/search'        
    = yield
  .grid_4
    = yield(:sidebar)

:

Rails 3.x, . Rails 3.

+4

if, , . , . , , @disable_sidebar -, false nil.

.container_12.clearfix
= render :partial => 'shared/flashes'
- unless @disable_sidebar
  .grid_8
    = render :partial => 'shared/search'        
    = yield
  .grid_4
    = yield(:sidebar)
- else
  .grid_12
  = render :partial => 'shared/search'        
  = yield
0

All Articles