51224bdd17878b3b19e8987e9bb336a2

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

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 !

5170ca260dbd2cdfd5a887a4dba7636f

Jeremy

July 31, 2008, July 31, 2008 14:08, permalink

1 rating. Login to rate!

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.

51224bdd17878b3b19e8987e9bb336a2

DG

August 1, 2008, August 01, 2008 04:57, permalink

No rating. Login to rate!

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

Cf8a610127d1108dfe67f673320b5fe5

cpjolicoeur

August 3, 2008, August 03, 2008 22:55, permalink

No rating. Login to rate!

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.

Your refactoring





Format Copy from initial code

or Cancel