2013-06-12 53 views
2

我知道這是一個廣泛的問題,但我沒有找到具體的答案,現在我覺得我只需要拉霰彈槍的方法。最常見的原因餘燼模板無法在rails應用中呈現

我試圖加載一個應用程序內的應用程序的一個燼。我已經ember_controller.rb:

class EmberController < FrontendController 
    layout 'ember' 
    def load 
    end 
end 

我的Rails的路線是這樣的:

MdmFrontEnd::Application.routes.draw do 

    resources :sessions, only: [:create, :new, :destroy] 

    match '/signin', to: 'sessions#new' 
    match '/signout', to: 'sessions#destroy', via: :delete 
    match '*path' => 'ember#load' 
    root to: 'ember#load' #makes the root of the app, the ember root. 
end 

我的軌道佈局是這樣的:

!!! 5 
%html 
    %head 
    %meta{charset:"utf-8"} 
    %title= t("layouts.mobile_manager") 
    %meta{name:"viewport", content:"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" } 
    %link{rel: "icon", type:"image/png", href:"/assets/favicon_16x16.png"} 
    = javascript_include_tag "i18n" 
    :javascript 
     window.locale = "<%= I18n.locale %>"; 
    = stylesheet_link_tag 'application', media: 'all' 
    = csrf_meta_tags 
    <!--[if lt IE 9]> 
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 

    -if Rails.env.production? 
     :javascript 
     var _gaq = _gaq || []; 
     _gaq.push(['_setAccount', 'UA-33246783-1']); 
     _gaq.push(['_trackPageview']); 
     (function() { 
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
     })(); 
    = render 'shared/js_constants' 
    = javascript_include_tag 'app_ember' 
    %body 

我在初始化一個新應用程序的餘燼app_ember.coffee與以下內容:

#= require jquery 
#= require jquery_ujs 
#= require handlebars 
#= require ember 
#= require_self 
#= require_tree ./app/routes 
#= require_tree ./app/controllers 
#= require_tree ./app/models 
#= require_tree ./app/templates 
#= require_tree ./app/views 

window.Mdm = Ember.Application.createWithMixins 
    LOG_TRANSITIONS: true 

    ajax: -> 
    $.ajax.apply(this, arguments) 

    getUrl: (path) -> 
    "/#{path}" 

然後,我的模板application.hbs和index.hbs與應用程序內的{{outlet}}一起使用。

但是,當我嘗試渲染根,我只是得到一個空白的屏幕。

我知道這是看到,但因爲在控制檯中模板的時候,我跑Ember.TEMPLATES它列出了每個模板對象。

我覺得它有問題B/T導軌和灰燼,但我不知道。

感謝您的任何想法!

編輯::我的控制檯

enter image description here

正如你所看到的,它加載我的模板對象,但隨後也說,它找不到應用程序或指數模板。我的模板目錄被命名爲和位於像其他目錄 - 模型,控制器等

回答

1

有很多怎麼回事,很難肯定地說。有些事情要考慮

  1. 如果您燼的應用已經開始正常,你應該會看到一些的console.log輸出。這將包括來自餘燼的DEBUG信息:哪些版本已加載。如果你沒有看到,你的環境出了問題。

  2. 由於您已設置LOG_TRANSITION: true,因此應該看到console.log消息,如:Transitioned into 'post.index',因爲路由器將轉換爲當前路由。如果您在頁面加載時未在控制檯中看到任何消息,則該應用無法正確引導。

  3. 通常當我有這樣的問題,那是因爲我的命名慣例不相符什麼燼期待。結果,我的代碼被忽略,並且燼正在使用生成的默認值。要了解什麼是引擎蓋下回事,創建應用程序時設置兩個屬性:

- 到位

LOG_ACTIVE_GENERATION: true, 
LOG_VIEW_LOOKUPS: true 

有了這個,你應該看到的console.log輸出每當燼生成路徑/控制器或呈現視圖。有了這一切的地方,你的console.log應該是這個樣子:

DEBUG: ------------------------------- 
DEBUG: Ember.VERSION : 1.0.0-rc.4 
DEBUG: Handlebars.VERSION : 1.0.0-rc.4 
DEBUG: jQuery.VERSION : 1.8.3 
DEBUG: ------------------------------- 
generated -> route:post.index Object {fullName: "route:post.index"} 
Rendering application with <App.ApplicationView:ember785> Object {fullName: "view:application"} 
Rendering post with <App.PostView:ember789> Object {fullName: "view:post"} 
generated -> controller:post.index Object {fullName: "controller:post.index"} 
Rendering post.index with default view <Ember._MetamorphView:ember796> Object {fullName: "view:post.index"} 
Transitioned into 'post.index' 

在這裏你可以看到正在發生什麼類,模板渲染和正在使用哪些視圖類。

+0

#1和#2都很好,我這樣做了,控制檯正在渲染輸出。非常感謝其他兩個屬性,我沒有意識到他們,他們可能讓我更接近了一步。正如你從我的編輯和我發佈的截圖中可以看到的,當我輸出Ember.TEMPLATES時,它會看到模板,但在它下面顯示它找不到應用程序或索引模板,因此它沒有渲染任何內容。任何想法,爲什麼這可能是?再次感謝邁克,我非常感謝。 – reknirt

+1

好的,我看到了問題。 Ember找不到任何模板,因爲它們都以「app /」作爲前綴。查看行:'找不到「應用程序」模板或視圖「?這意味着,燼正在尋找'Ember.TEMPLATES ['application']',它返回undefined。不知道你用什麼來編譯/加載句柄模板,但它將「app /」添加到所有模板名稱的前面,您需要更改某些配置以刪除該前綴。可以像移動模板一樣簡單 - 它們都在「應用程序」子文件夾內嗎? –

+0

啊,我明白了。文件結構是rails_app - > app - > assets - > javascripts - > app - > templates - > application.hbs&index.hbs – reknirt