def determine_layout
action = params[:action]
if action == "index" || action == "show" || action == "edit" || action == "update"
"application"
else
"sessions"
end
end
Refactorings
No refactoring yet !
Kryckan
September 11, 2009, September 11, 2009 23:05, permalink
Never mind, found a nice solution:
def determine_layout
action = params[:action]
%w(index show edit update).include?(action) ? "application" : "sessions"
end
hellekin
September 12, 2009, September 12, 2009 02:04, permalink
You don't even need to assign action
def determine_layout
%w(index show edit update).include?(params[:action]) ? "application" : "sessions"
end
Martin Plöger
September 14, 2009, September 14, 2009 12:15, permalink
Not that short, but IMHO more readable
def determine_layout
case params[:action]
when 'index', 'show', 'edit', 'update' then 'application'
else 'sessions'
end
end
Srini
September 26, 2009, September 26, 2009 15:30, permalink
A obfuscation 'refactoring' :-)
def determine_layout
{ true => 'application', false => 'sessions' }[%w(index show edit update).include?(action_name)]
end
The code looks ugly and I think it could be written much better.