Home controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class HomeController < ApplicationController layout :set_layout def index @newalert = Newalert.find(:all) render :partial=>"newalert/new_alert",:layout=> :set_layout end protected def set_layout logged_in? ? "application" : "home" end end
Refactorings
No refactoring yet !
Jeremy
July 31, 2008, July 31, 2008 14:08, permalink
Partials don't use the layout by default. It seems strange that you'd want to render a partial from your index action... I'm guessing that's not ultimately what you want to do.
DG
August 1, 2008, August 01, 2008 04:57, permalink
Hi Jeremy
Thanks for your explanation. Yes you are right I am not rendering partial from my action.
But is it wrong to do so? because in other many application code I seen the same thing.
Thanks
DG
cpjolicoeur
August 3, 2008, August 03, 2008 22:55, permalink
If you see partials being rendered directly in controller actions in other code, well, that other code is bad as well.
You really generally only render partials from view files, not directly from controller action methods.
In below code snippet.
- I need to compulsory pass an layout option to render partial line. As you can see I am all ready setting the layout in set_layout method.
- If I remove the (:layout=> :set_layout) from render line then it doesn't render the proper layout.
If anyone explain me why it's happening like that or am I doing something wrong?
Thanks
DG