ruby-on-rails - 在 ruby​​ on rails 应用程序中使用 application.html.erb 以外的布局?

标签 ruby-on-rails templates

如何在 RoR 应用程序中创建和使用新模板而不是 application.html.erb?我需要更改哪些设置才能拥有另一个模板?

最佳答案

实际上,默认情况下,所有 Controller 都会在 /views/layouts 文件夹中搜索同名布局,并回退到 application.html.erb。例如,UsersController 将搜索 users.html.erb。无论如何,要使用其他布局,请在您的 Controller 旁边添加:

class UsersController < ApplicationController
  layout 'custom'
end

关于ruby-on-rails - 在 ruby​​ on rails 应用程序中使用 application.html.erb 以外的布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10945967/

相关文章:

ruby-on-rails - 为什么 Rails Gemfile 默认为 https 而 http 使 bundler 更快?

ruby-on-rails - RSpec 共享示例 - 将数据传递给共享规范

ruby-on-rails - Ruby URI::InvalidURIError: Bad URI(is not URI?) 除了编码

c++ - 如何根据模板参数更改值?

Azure Pipelines "Require Template"检查不起作用

c++ - 从成员函数类型中删除 const 的特征?

c++ - 文字 charT 数组

ruby-on-rails - 将 Rails 3.0.9 迁移到 Rails 3.1 时遇到问题? ActiveRecord::连接未建立

ruby-on-rails - Gemfile 中的环境变量

c++ - 使用模板的 CUDA 设备阵列实现