2014-11-22 73 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