views:

125

answers:

4

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

A: 

Decide the layout in the controller rather then the model. Your ProjectsController can use it's own ProjectLayout and MessagesController can then use the normal layout if you wish.

Hates_
+1  A: 

You can only apply layouts at the Controller level:

class MessagesController < ApplicationController
  layout :project
end

Layout method documentation has an example on how to do conditional layouts

Peer Allan
A: 

Also, since the question is unclear, you can also set layout for only one action with the render option.

render :action => 'new', :layout => 'layoutname'
Matchu
+2  A: 

this may help you

class MessagesController < ApplicationController
  layout :get_layout

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

end
Alvaro Talavera