ror中的多个布局 [英] Multiple layouts in ror

查看:65
本文介绍了ror中的多个布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天刚开始使用Ruby on Rails.在我的layouts/application.html.erb中,我有:

Just started Ruby on Rails yesterday. In my layouts/application.html.erb i have:

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag    "application", media: "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>  
  </head>
  <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <%= yield %>
    </div>
    <%= render 'layouts/footer' %>
  </body>
</html> 

来自php-> codeigniter背景,我假设渲染类似于$ this-> load-> view('');在codeigniter中.
尽管此方法工作正常,但我希望有多个应用程序布局文件,例如

Coming from php ->codeigniter background, i'm assuming render is similar to $this->load->view(''); in codeigniter.
Although this works fine, i would like to have multiple application layout files e.g

  1. 布局/应用默认设置
  2. 布局/应用全角(用于全角页面)
  3. 等等.

在codeigniter中,您只需声明要使用的模板/布局文件中的哪个,但由于Rails上的ruby有点神奇(它为您做了很多事情),我假设它默认情况下调用应用程序布局.我想知道是否有一种方法可以选择我想要的布局文件?

In codeigniter you simply declare which of the templates/layout files you wish to use but as ruby on rails is a bit magical(It does a lot of things for you), i'm assuming it calls the application layout by default. I was wondering if there's a way to choose what layout file i want?

推荐答案

您正在寻找

You're looking for the layout method.

本Rails指南将为您提供帮助,特别是

This Rails Guide will help you, specifically Finding Layouts. I'd provide more detail here, but the previously mentioned documentation and guide provide more than enough examples and usage instruction.

这篇关于ror中的多个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆