我知道这是一个广泛的问题,但我没有找到具体的答案,现在我觉得我只需要拉霰弹枪的方法。最常见的原因余烬模板无法在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导轨和灰烬,但我不知道。
感谢您的任何想法!
编辑::我的控制台
正如你所看到的,它加载我的模板对象,但随后也说,它找不到应用程序或指数模板。我的模板目录被命名为和位于像其他目录 - 模型,控制器等
#1和#2都很好,我这样做了,控制台正在渲染输出。非常感谢其他两个属性,我没有意识到他们,他们可能让我更接近了一步。正如你从我的编辑和我发布的截图中可以看到的,当我输出Ember.TEMPLATES时,它会看到模板,但在它下面显示它找不到应用程序或索引模板,因此它没有渲染任何内容。任何想法,为什么这可能是?再次感谢迈克,我非常感谢。 – reknirt
好的,我看到了问题。 Ember找不到任何模板,因为它们都以“app /”作为前缀。查看行:'找不到“应用程序”模板或视图“?这意味着,烬正在寻找'Ember.TEMPLATES ['application']',它返回undefined。不知道你用什么来编译/加载句柄模板,但它将“app /”添加到所有模板名称的前面,您需要更改某些配置以删除该前缀。可以像移动模板一样简单 - 它们都在“应用程序”子文件夹内吗? –
啊,我明白了。文件结构是rails_app - > app - > assets - > javascripts - > app - > templates - > application.hbs&index.hbs – reknirt