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
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
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.
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
Also, since the question is unclear, you can also set layout for only one action with the render option.
render :action => 'new', :layout => 'layoutname'
this may help you
class MessagesController < ApplicationController
layout :get_layout
def get_layout
@project? ? 'ProjectLayout' : 'NormalLayout'
end
end