我知道這是一個廣泛的問題,但我沒有找到具體的答案,現在我覺得我只需要拉霰彈槍的方法。最常見的原因餘燼模板無法在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