【发布时间】:2017-05-26 08:23:21
【问题描述】:
我正在将我的第一个 Ember 应用程序集成到 Rails 项目中。我添加了ember-cli-rails gem 并运行了初始化程序,这样我就有了一个看起来像这样的config/initializers/ember.rb 文件:
EmberCLI.configure do |c|
c.app :products, path: 'products'
end
我的 Ember 应用程序位于我的 Rails 应用程序根目录中,名为 products。除了生成默认的 Ember 应用程序之外,我什么也没做。
我在 Rails 中为ProductsController 创建了一个特定的布局。这是app/views/products.html.erb。我添加了以下几行:
<%= include_ember_script_tags :products %>
<%= include_ember_stylesheet_tags :products %>
我还编辑了 Ember 应用程序的 router.js 文件,因为我没有在根 URL 处提供 Ember 应用程序:
var Router = Ember.Router.extend({
rootURL: config.baseURL, // added this line
location: config.locationType
});
最后我在 Ember 应用中更改了 config/environments.js
var ENV = {
modulePrefix: 'products',
environment: environment,
baseURL: '/products', // changed from '/' to '/products'
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
这个控制器的索引页面很好。它正在尝试加载 Ember 文件,但我收到错误消息:
Uncaught Error: Assertion Failed: rootURL must end with a trailing forward slash e.g. "/app/"
ember-cli-rails 的说明不包含尾部斜杠。
如果我添加了斜杠,我会得到:
Uncaught Error: Assertion Failed: Path /products does not start with the provided rootURL /products/
我意识到我在这里的第一个 Ember 应用程序中可能遗漏了一些非常基本的东西。非常感谢您提供的任何帮助。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 ember.js ember-cli ruby-on-rails-4.2