【问题标题】:Application layout not shown in Rails 3Rails 3 中未显示应用程序布局
【发布时间】:2013-03-15 10:18:17
【问题描述】:

我查看了我的基本起始代码,以确保我没有拼写错误。你可能会看到我做的一些事情。我无法让我的 application.html.erb 出现。我的基本应用程序只有一个模型。我还没有安装控制器并首先通过 TDD 查看工作模型。我安装了“twitter-bootstrap-rails”并按照安装程序进行操作。在安装引导程序之前我没有测试视图。我的 ruby​​ 是 1.9.3,我的 rails 应用程序是 3.2.11 这是我的 routes.rb

 root :to => 'weather#index'
 resources :weather

这是我适用的 Gemfile

 group :assets do
   gem 'sass-rails', '~> 3.2'
   #gem 'bootstrap-sass', '~> 2.3.1.0' bailed when it seemed to conflict
   gem 'coffee-rails', '~> 3.2.1'
   gem 'uglifier', '>= 1.0.3'
 end

这是我的控制器:

 class WeatherController < ActionController::Base
   def index
   end
 end

这是我的观点/天气/index.html.erb:

 test

我的 views/layouts/application.html.erb 具有 twitter-bootstrap-rails 布局和

我知道我的控制器没有以 Rails 方式命名。当我将其更改为所有适当位置的天气时,结果是相同的。我得到了没有应用程序 html 代码的单词测试。结果的来源只是没有 html 标头或输出的“测试”。如果我将 layout: 'application' 放在 index 操作中,我会看到它,但不会显示 index.html.erb 的内容。我看过 SO,但它们似乎并不适用或工作。在这方面是新手是一个障碍。我确定我忽略了一些愚蠢的事情。谢谢收看,山姆

【问题讨论】:

  • 你用一个简单的 application.html.erb 文件测试过它吗?例如只是没有引导程序的 HTML 框架?也许在 index 操作中设置一个 @test = test 变量并从您的测试 index.html.erb 布局中调用它?
  • 是的。在我的 application.html.erb 文件中,我抽出 标记中的所有内容并得到相同的结果。该变量通过正常,因此它知道它是一个 Rails erb 文件。谢谢。
  • 您在答案中尝试过以下解决方案吗?从 ApplicationController 继承?

标签: ruby-on-rails twitter-bootstrap


【解决方案1】:

你的控制器应该继承自 ApplicationController 而不是 ActionController::Base

刚才提到了我自己关于完全相同问题的问题:Having to explicitly render :layout => 'application' in controller actions in my Rails 3 app

改变对几个人有用。

【讨论】:

  • 非常接近。这次和之前我得到了不同的错误。最新的是
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 2019-07-16
  • 2012-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多