02 - creating a layout for your header and footer.rb

来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 66 行

RB
66
字号
<html>  <head>    <title>My Website</title> </head>  <body>    <%= @content_for_layout %>  </body></html>#---class StatusController < ActionController:Base  def index    @title = "System Status"  endend#---<html>  <head>    <title>My Website - <%= @title %></title>  </head>  <body>    <%= @content_for_layout %>  </body></html>#---class FooController < ActionController:Base  # Force the layout for /foo to be app/views/layouts/bar.rhtml,  # not app/view/layouts/foo.rhtml.  layout 'bar'end#---class FooController < ActionController:Base  layout 'bar'      def count    @data = [1,2,3]    render :layout => 'count'  endend#---class FooController < ActionController:Base  layout 'bar', :except => 'count'end#---class FooController < ActionController:Base  layout :figure_out_layout  private    def figure_out_layout    if action_name =~ /pretty/      'pretty'          # use pretty.rhtml for the layout    else      'standard'        # use standard.rhtml    end  endend#---class FooController < ActionController:Base  layout lambda { |controller| controller.logged_in? ? 'user' : 'guest' }end#---<%= render :partial => 'layouts/header' %>... your view's content goes here ...<%= render :partial => 'layouts/footer' %>#---

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?