您可以使用 ember-cli-rails 来实现此目的。
您可以配置 Rails 以将 ember 应用程序安装到特定路径。
# config/routes.rb
Rails.application.routes.draw do
mount_ember_app :frontend, to: "/ember"
end
如果需要,您甚至可以使用与应用程序的其余部分相同的 rails 布局,并让 ember 仅在某个元素中呈现。
<%# app/views/posts/index.html.erb %>
<div id="ember-application"></div>
<%= include_ember_script_tags :frontend %>
<%= include_ember_stylesheet_tags :frontend %>
诀窍是rootElement
在 ember 端的 config/environment.js 中进行设置。
/* frontend/config/environment.js */
/* eslint-env node */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'frontend',
environment: environment,
baseURL: '/',
locationType: 'auto',
//locationType: 'none',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
rootElement: '#ember-application'
},
如果您需要更多帮助,请告诉我。