using alternate layout depending on action

This commit is contained in:
Dan Buch 2011-08-09 07:03:28 -04:00
parent 391a4c186f
commit 9d42948abe
5 changed files with 39 additions and 8 deletions

View File

@ -1,15 +1,18 @@
class FooController < ApplicationController
layout 'bar', :except => 'count'
layout :figure_out_layout
def index
if request["die"]
throw Exception.new 'omg huh?'
end
def pretty
end
def figure_out_layout
if action_name =~ /pretty/
'pretty'
else
'standard'
end
end
def count
@data = [1,2,3]
render :layout => 'count'
end
end

View File

@ -0,0 +1,2 @@
<h1>Foo#pretty</h1>
<p>Find me in app/views/foo/pretty.html.erb</p>

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>My Pretty Website - <%= @title %></title>
<style type="text/css">
body {
background: #f99;
color: #222;
}
</style>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>My Plain Website - <%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@ -1,4 +1,6 @@
Hodgepodge::Application.routes.draw do
get "foo/pretty"
get "foo/count"
get "foo/index"