Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In rails is it possible to load class layout dynamically?

I need message to have a different layout in project, is it possible in rails to do something like this?

Class Messages::New < @project? ProjectLayout : NormalLayout
end  #i treid this, don't work, since @project has not been initiated.

thanks

like image 364
ez. Avatar asked Aug 13 '09 22:08

ez.


People also ask

What does layout do in Rails?

A layout defines the surroundings of an HTML page. It's the place to define a common look and feel of your final output. Layout files reside in app/views/layouts. The process involves defining a layout template and then letting the controller know that it exists and to use it.


1 Answers

this may help you

class MessagesController < ApplicationController
  layout :get_layout

  def get_layout
    @project? ? 'ProjectLayout' : 'NormalLayout'
  end

end
like image 105
Alvaro Talavera Avatar answered Oct 04 '22 22:10

Alvaro Talavera