Application.html.haml文件未呈现

时间:2014-11-22 18:09:11

标签: ruby-on-rails haml

我是ROR的新手。我正在开发一个使用erb文件的项目,现在我已将它们转换为haml。

我已经在其他帖子中提到了 haml gem ,但没有运气! 并使用导轨4。

问题是这个application.haml文件没有呈现我不知道为什么。 请帮忙 如果需要其他任何信息,请告诉我 这里是application.html.haml

!!!
%html
  %head
    %title PipeCast
    %link{:rel => "stylesheet", :href => "assets/stylesheets/application.css"}
    = csrf_meta_tags
    = render 'layouts/shim'
  %body
    = render 'layouts/header'
    = yield

这里是application_controller.rb

class ApplicationController < ActionController::Base

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  # protect_from_forgery with: :null_session

  # before_filter :set_cache_buster
#
  # def set_cache_buster
    # response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    # response.headers["Pragma"] = "no-cache"
    # response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  # end
#
end

这是页面控制器扩展应用程序控制器,但它不呈现应用程序布局

class PagesController < ApplicationController
  def home 

     @greeting = "Hello Welcome to Ruby Web Application"
  end
end

服务器日志您可以在此处注意,虽然所有文件都是haml但是渲染 pages / home.html.erb 不知道从何处!

=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-11-23 01:13:29] INFO  WEBrick 1.3.1
[2014-11-23 01:13:29] INFO  ruby 2.1.0 (2013-12-25) [x86_64-darwin14.0]
[2014-11-23 01:13:29] INFO  WEBrick::HTTPServer#start: pid=20082 port=3000


Started GET "/" for 127.0.0.1 at 2014-11-23 01:35:39 +0530
Processing by PagesController#home as HTML
  Rendered pages/home.html.erb (15.2ms)
Completed 200 OK in 79ms (Views: 53.9ms | ActiveRecord: 0.0ms)


Started GET "/" for 127.0.0.1 at 2014-11-23 01:36:27 +0530
Processing by PagesController#home as HTML
  Rendered pages/home.html.erb (0.1ms)
Completed 200 OK in 3ms (Views: 2.9ms | ActiveRecord: 0.0ms)


Started GET "/" for 127.0.0.1 at 2014-11-23 01:36:27 +0530
Processing by PagesController#home as HTML
  Rendered pages/home.html.erb (0.1ms)
Completed 200 OK in 2ms (Views: 1.9ms | ActiveRecord: 0.0ms)


Started GET "/" for 127.0.0.1 at 2014-11-23 01:36:28 +0530
Processing by PagesController#home as HTML
  Rendered pages/home.html.erb (0.1ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)

1 个答案:

答案 0 :(得分:1)

实际上你不需要布局,只需要简单的部分。

= render 'layouts/header'

使用此类构造时,您尝试渲染部分内部布局。

确保其名称为&#39; app / views / layouts / _header.html.haml&#39;

按惯例,partials应从下划线字符开始。