using alternate layout depending on action
This commit is contained in:
parent
391a4c186f
commit
9d42948abe
@ -1,15 +1,18 @@
|
|||||||
class FooController < ApplicationController
|
class FooController < ApplicationController
|
||||||
layout 'bar', :except => 'count'
|
layout :figure_out_layout
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if request["die"]
|
end
|
||||||
throw Exception.new 'omg huh?'
|
|
||||||
|
def pretty
|
||||||
|
end
|
||||||
|
|
||||||
|
def figure_out_layout
|
||||||
|
if action_name =~ /pretty/
|
||||||
|
'pretty'
|
||||||
|
else
|
||||||
|
'standard'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def count
|
|
||||||
@data = [1,2,3]
|
|
||||||
render :layout => 'count'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
2
cookbook/015/hodgepodge/app/views/foo/pretty.html.erb
Normal file
2
cookbook/015/hodgepodge/app/views/foo/pretty.html.erb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<h1>Foo#pretty</h1>
|
||||||
|
<p>Find me in app/views/foo/pretty.html.erb</p>
|
15
cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb
Normal file
15
cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb
Normal 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>
|
@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>My Plain Website - <%= @title %></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<%= yield %>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,4 +1,6 @@
|
|||||||
Hodgepodge::Application.routes.draw do
|
Hodgepodge::Application.routes.draw do
|
||||||
|
get "foo/pretty"
|
||||||
|
|
||||||
get "foo/count"
|
get "foo/count"
|
||||||
|
|
||||||
get "foo/index"
|
get "foo/index"
|
||||||
|
Loading…
Reference in New Issue
Block a user