From 9d42948abe7c908cc85b4231ad7b6c589d815044 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 9 Aug 2011 07:03:28 -0400 Subject: [PATCH] using alternate layout depending on action --- .../app/controllers/foo_controller.rb | 19 +++++++++++-------- .../hodgepodge/app/views/foo/pretty.html.erb | 2 ++ .../app/views/layouts/pretty.html.erb | 15 +++++++++++++++ .../app/views/layouts/standard.html.erb | 9 +++++++++ cookbook/015/hodgepodge/config/routes.rb | 2 ++ 5 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 cookbook/015/hodgepodge/app/views/foo/pretty.html.erb create mode 100644 cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb create mode 100644 cookbook/015/hodgepodge/app/views/layouts/standard.html.erb diff --git a/cookbook/015/hodgepodge/app/controllers/foo_controller.rb b/cookbook/015/hodgepodge/app/controllers/foo_controller.rb index 64959f8..4a38782 100644 --- a/cookbook/015/hodgepodge/app/controllers/foo_controller.rb +++ b/cookbook/015/hodgepodge/app/controllers/foo_controller.rb @@ -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 diff --git a/cookbook/015/hodgepodge/app/views/foo/pretty.html.erb b/cookbook/015/hodgepodge/app/views/foo/pretty.html.erb new file mode 100644 index 0000000..bfdd816 --- /dev/null +++ b/cookbook/015/hodgepodge/app/views/foo/pretty.html.erb @@ -0,0 +1,2 @@ +

Foo#pretty

+

Find me in app/views/foo/pretty.html.erb

diff --git a/cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb b/cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb new file mode 100644 index 0000000..945a4c4 --- /dev/null +++ b/cookbook/015/hodgepodge/app/views/layouts/pretty.html.erb @@ -0,0 +1,15 @@ + + + + My Pretty Website - <%= @title %> + + + + <%= yield %> + + diff --git a/cookbook/015/hodgepodge/app/views/layouts/standard.html.erb b/cookbook/015/hodgepodge/app/views/layouts/standard.html.erb new file mode 100644 index 0000000..18294ba --- /dev/null +++ b/cookbook/015/hodgepodge/app/views/layouts/standard.html.erb @@ -0,0 +1,9 @@ + + + + My Plain Website - <%= @title %> + + + <%= yield %> + + diff --git a/cookbook/015/hodgepodge/config/routes.rb b/cookbook/015/hodgepodge/config/routes.rb index 89b9e00..20f0926 100644 --- a/cookbook/015/hodgepodge/config/routes.rb +++ b/cookbook/015/hodgepodge/config/routes.rb @@ -1,4 +1,6 @@ Hodgepodge::Application.routes.draw do + get "foo/pretty" + get "foo/count" get "foo/index"