可能在一个Rails应用程序中有多个ember.js应用程序? [英] Possible to have multiple ember.js apps in one Rails app?

查看:120
本文介绍了可能在一个Rails应用程序中有多个ember.js应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Ember应用程序,需要与另一个带有Rails后端(使用ember-rails gem)的Ember应用程序进行合并。有可能通过Rails后端连接两个完全独立的ember应用程序吗?将有一些共享资源(通过Rails),但是否则应用程序是非常不同的,它将是理想的一个Rails应用程序,而不是为每个Ember应用程序制作两个单独的Rails应用程序...



谢谢

解决方案

是的,完全可能的。



您将需要每个应用程序的Rails路线。例如/ app1和/ app2



我有一个单独的JavaScript清单文件,我的ember应用程序和我的Rails应用程序,但我不明白为什么你不能组合如果你想要的话,将ember应用程序放入application.js清单文件。



您可以按照以下方式实例化您的Ember应用程序:

  App = Ember.Application.create({
rootElement:'#PUT_YOUR_ROOT_DOM_ELEMENT_HERE',
Resolver:Ember.DefaultResolver.extend({
resolveTemplate:function(parsedName)){
parsedName.fullNameWithoutType = PUT_THE_RELATIVE_RAILS_URL_FOR_YOR_EMBER_APP_HERE /+ parsedName.fullNameWithoutType;
return this._super(parsedName);
}
})
});

默认行为是附加到DOM的底部,您可以指定如上所示的rootElement如果您从Rails应用程序重新使用页眉或页脚,则很有用。上面的解决方案显示了如何为Ember应用程序指定Rails url,以使Ember url相对于它。



我从这里得到这个解决方案:
<一个href =https://stackoverflow.com/questions/15859552/ember-rails-and-namespaced-templates> Ember-Rails和命名空间模板



更新:



您还应该在路由器中指定相对的Rails url

  App.Router.reopen({
rootURL:'/ PUT_THE_RELATIVE_RAILS_URL_FOR_YOR_EMBER_APP_HERE'
});


I'm working on an Ember app that will need to be merged with another ember app with a Rails back-end (using ember-rails gem). Is it possible to have two totally separate ember apps connected by a Rails back-end? There will be some shared resources (through Rails) but otherwise the apps are very different and it would be ideal to be able to serve them both with one Rails app as opposed to making two separate Rails apps for each Ember app...

thanks

解决方案

Yes, totally possible.

You will need a Rails route for each app. eg /app1 and /app2

I have a separate javascript manifest file for my ember app and for my Rails app, but I don't see why you can't combine both ember apps into application.js manifest file if you want to.

You can instantiate your Ember app as follows:

App = Ember.Application.create({
  rootElement: '#PUT_YOUR_ROOT_DOM_ELEMENT_HERE',
  Resolver: Ember.DefaultResolver.extend({
    resolveTemplate: function(parsedName) {
      parsedName.fullNameWithoutType = "PUT_THE_RELATIVE_RAILS_URL_FOR_YOR_EMBER_APP_HERE/" + parsedName.fullNameWithoutType;
      return this._super(parsedName);
    }
  })
});

Embers default behaviour is to attach to the bottom of the DOM, You can specify a rootElement as shown above.. Useful if you re-use header or footer from Rails app. Solution above shows how you specify your Rails url for the ember app, so that Ember urls are relative to it.

I got this solution from here: Ember-Rails and namespaced templates

UPDATE:

You should also specify the relative Rails url in the Router

App.Router.reopen({    
  rootURL: '/PUT_THE_RELATIVE_RAILS_URL_FOR_YOR_EMBER_APP_HERE'
});

这篇关于可能在一个Rails应用程序中有多个ember.js应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆