C8c549e9bb39135192db53d238e19f3e

The code looks ugly and I think it could be written much better.

def determine_layout
    action = params[:action]
    if action == "index" || action == "show" || action == "edit" || action == "update"
      "application"
    else
      "sessions"
    end  
  end

Refactorings

No refactoring yet !

C8c549e9bb39135192db53d238e19f3e

Kryckan

September 11, 2009, September 11, 2009 23:05, permalink

No rating. Login to rate!

Never mind, found a nice solution:

def determine_layout
    action = params[:action]
    %w(index show edit update).include?(action) ? "application" : "sessions"  
  end
2cfbd4a81664e5d31b4b2fd0ace83c42

hellekin

September 12, 2009, September 12, 2009 02:04, permalink

1 rating. Login to rate!

You don't even need to assign action

def determine_layout
    %w(index show edit update).include?(params[:action]) ? "application" : "sessions"
  end
E8f0d6e9bc8bca695b3c5bdf75cdcc03

Martin Plöger

September 14, 2009, September 14, 2009 12:15, permalink

No rating. Login to rate!

Not that short, but IMHO more readable

def determine_layout
  case params[:action]
    when 'index', 'show', 'edit', 'update' then 'application'
    else                                        'sessions'
  end
end
115ee8200bbce24970b06276a54160c4

Srini

September 26, 2009, September 26, 2009 15:30, permalink

No rating. Login to rate!

A obfuscation 'refactoring' :-)

def determine_layout
    { true => 'application', false => 'sessions' }[%w(index show edit update).include?(action_name)]
  end

Your refactoring





Format Copy from initial code

or Cancel