Ruby on rails 如何修复Rails中的此Ember CLI错误?
我正在Rails项目中集成我的第一个Ruby on rails 如何修复Rails中的此Ember CLI错误?,ruby-on-rails,ruby-on-rails-4,ember.js,ember-cli,ruby-on-rails-4.2,Ruby On Rails,Ruby On Rails 4,Ember.js,Ember Cli,Ruby On Rails 4.2,我正在Rails项目中集成我的第一个Ember应用程序。我已经添加了ember cli railsgem并运行了初始化程序,因此我有一个config/initializers/ember.rb文件,如下所示: EmberCLI.configure do |c| c.app :products, path: 'products' end 我的Ember应用程序位于我的Rails应用程序根目录中,名为products。目前,除了生成默认的余烬应用程序,我什么也没做 我已经在Rails中为Pro
Ember
应用程序。我已经添加了ember cli rails
gem并运行了初始化程序,因此我有一个config/initializers/ember.rb
文件,如下所示:
EmberCLI.configure do |c|
c.app :products, path: 'products'
end
我的Ember应用程序位于我的Rails应用程序根目录中,名为products
。目前,除了生成默认的余烬应用程序,我什么也没做
我已经在Rails中为ProductsController
创建了一个特定的布局。它是app/views/products.html.erb。我添加了以下行:
<%= include_ember_script_tags :products %>
<%= include_ember_stylesheet_tags :products %>
最后,我在我的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
}
},
该控制器的索引页显示良好。它正在尝试加载余烬文件,但我收到一个错误:
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/
我意识到我在这里的第一个余烬应用程序中可能缺少一些非常基本的东西。非常真诚地感谢您提供的任何帮助。我找到了答案
因此,继续并将尾部斜杠添加到baseURL
。然后按照上面链接的帖子中的说明进行操作,我将在这里进行总结:
class YourEmberAppController
before_action :ensure_trailing_slash
respond_to :html, :js
def index
render :index
end
def vehicles
end
def save
end
private
def ensure_trailing_slash
unless trailing_slash?
redirect_to url_for(params.merge(trailing_slash: true)), status: 301
end
end
def trailing_slash?
request.env['REQUEST_URI'].match(/[^\?]+/).to_s.last == '/'
end
end
这样做,您的页面将显示“欢迎来到Ember”。在Rails的
路线中。rb
:
get 'products', to: redirect('/products/'), constraints: lambda { |req| req.env['REQUEST_URI'].last != '/' }
我还了解到,这是一种在Rails应用程序中包含Ember应用程序的老式方法。
get 'products', to: redirect('/products/'), constraints: lambda { |req| req.env['REQUEST_URI'].last != '/' }