我在我的ember-rails应用程序中创建了一个Ember组件,但由于某些不可思议的原因,它没有读取我的主要组件js文件。
我正在使用我的组件..
# app/assets/javascripts/templates/comment.hbs
<p>{{time-ago createdAt=comment.created_at}}</p>
这是组件模板,我可以看到它是渲染,因为我可以看到静态文本“已发布”显示在浏览器中,但组件js文件中定义的任何内容只输出空白,例如{{doesNotWork}}输出什么都没有。
# app/assets/javascripts/tenmplates/components/time-ago.js
<p>posted <strong>{{timeAgo}} {{doesThisWork}}</strong></p>
组件js文件因为没有我在这里定义的变量而无法加载,我似乎可以渲染到组件模板中
# app/assets/javascripts/components/time-ago.js
App.TimeAgoComponent = Ember.Component.extend({
timeAgo: '',
oldTimeAgo: '',
doesThisWork: 'shows blank rather than this message',
clock: function() {
var newTimeAgo = moment(this.get('createdAt')).fromNow();
if (this.get('oldTimeAgo') !== newTimeAgo ) {
this.set('timeAgo', moment(this.get('createdAt')).fromNow());
}
Ember.run.later(this, this.clock, 1000 * 10);
}.on('didInsertElement')
});
我的直觉是ember-rails如何渲染或者没有在app / assets / javascripts / components中渲染文件有什么问题可能会出现问题?
[编辑1:根据评论查询添加我的rails js文件]
这是我的rails js文件。请注意,ember应用程序位于我的rails应用程序中的路径/文档上。
# app/assets/javascripts/docs.js.coffee
#= require handlebars
#= require ember
#= require ember-data
#= require remarkable
#= require moment
#= require ember-devise-simple-auth/globals
#= require_tree ./templates
#= require_tree ./components
#= require_self
#= require app
#app / assets / javascripts / application.js.coffee
#= require jquery
#= require jquery_ujs
#= require jquery.timeago
#= require turbolinks
#= require bootstrap
#= require activities
#= require collaborators
#= require dashboard
#= require plans
#= require profiles
#= require projects
#= require roles
#= require sections
#= require templates
#= require subscriptions
#= require select2
[编辑2:我想知道app / javascripts / components路径是否加载]
我在rails中找到了我可以从rails console运行此命令。
>> y Rails.application.config.assets.paths
---
- /Users/richie/Projects/bimbicycle/app/assets/images
- /Users/richie/Projects/bimbicycle/app/assets/javascripts
- /Users/richie/Projects/bimbicycle/app/assets/stylesheets
- /Users/richie/Projects/bimbicycle/vendor/assets/components
- /Users/richie/Projects/bimbicycle/vendor/assets/ember
- /Users/richie/Projects/bimbicycle/vendor/assets/fonts
- /Users/richie/Projects/bimbicycle/vendor/assets/images
- /Users/richie/Projects/bimbicycle/vendor/assets/javascripts
- /Users/richie/Projects/bimbicycle/vendor/assets/stylesheets
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/bootstrap-sass-3.1.1.0/vendor/assets/fonts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/bootstrap-sass-3.1.1.0/vendor/assets/javascripts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/font-awesome-sass-4.0.3.2/vendor/assets/fonts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/font-awesome-sass-4.0.3.2/vendor/assets/stylesheets
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/xray-rails-0.1.14/app/assets/javascripts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/xray-rails-0.1.14/app/assets/stylesheets
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/select2-rails-3.5.7/app/assets/images
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/select2-rails-3.5.7/app/assets/javascripts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/select2-rails-3.5.7/app/assets/stylesheets
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/turbolinks-2.1.0/lib/assets/javascripts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/jquery-rails-3.0.4/vendor/assets/javascripts
- /Users/richie/.rvm/gems/ruby-2.0.0-p481/gems/coffee-rails-4.0.1/lib/assets/javascripts
- !ruby/object:Pathname
path: /Users/richie/Projects/bimbicycle/vendor/assets/components
=> nil
最后请注意与供应商/资产/组件相关的错误,但我不确定这是否与我的问题有关,因为我的组件位于app / assets / components下。
想知道,有没有更好的rails表示要检查require_tree ./components是否正在加载我的time-ago.js文件?