2014-11-22 74 views
1

我是ROR的新手。我正在使用erb文件的项目,现在我已经将它们转换为haml。Application.html.haml文件未呈现

我已经安装了哈姆宝石正如其他帖子中提到的,但没有运气! 并使用导轨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 

Server日志你可以尽管所有文件都是HAML这里需要注意的却是呈现页/ 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) 
+0

先在'%body'标记下移动'= render'layouts/shim''。 – 2014-11-22 18:34:35

+0

我做了你说的,但没有运气! – Vishal 2014-11-22 18:37:00

+0

你有没有其他'layouts'? – 2014-11-22 18:38:10

回答

1

其实你不需要布局,只是简单的部分。

= render 'layouts/header' 

当你使用这样的构造时,你试图呈现部分内部布局。

确保,它的名字是“应用程序/视图/布局/ _header.html.haml”

通过约定的谐音应该从下划线开始。

+0

标题只有一个部分,并带有以名称作为前缀的下划线! – Vishal 2014-11-22 19:59:08

+0

,你有'app/views/pages/index.html.haml'视图吗? – 2014-11-22 20:03:41

+0

我在route.rb – Vishal 2014-11-22 20:11:35