2013-06-12 30 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