2

we have a classical Rails4 app that we want to take a step further using AngularJS (Ember would do, even Backbone), but the problem is that we don't want a fully Angular SPA using Rails just as the API endpoint. What we want to do is to serve the SPA only in parts of the app such as for example the search page being SPA, but the user's profile page being a classical Rails Controller/view...

So, user comes to /homepage and is served Angular.js, Templates etc., but when he goes to /users/3 he is served a classical Rails view..

What are your suggestions on this? I googled and couldn't find a good resource on the topic. I found a lot of "TodoMVC's" aps, but no Rails app with parts being "TodoMVC" Everyone is talking about Ember.js/AngularJS + Rails API. No hybrid mentioned.

The question comes down to:

  • Including AngularJS library into application.js and serving it always?
  • Organizing angular controller/view/directives under javasript/angular/ ?
  • The problems we might find down the way?
luigi7up
  • 5,779
  • 2
  • 48
  • 58
  • I talked about that lately: http://slides.com/apneadiving/rails-and-angular#/ hybrids are tough :) for js, you have it minimized in a single file, so keep it – apneadiving Sep 23 '14 at 09:40

1 Answers1

3

I have a hybrid app, You can see the Rails app at http://www.big5boutique.com

You can see the Ember.js app at http://www.big5boutique.com/itinerary-builder/

Basically, I have built a regular Rails app, that is served with a single application.js and application.css for any page you visit.

However, if you visit the Single Page App, then I use the same application.css but include a different javascript manifest file, which only includes the Ember / Angular code and leaves out the normal jQuery based code for the rest of the app.

Then in application.html.erb I have some code that checks the request url an includes the appropriate javascript.

Both the Rails app and Ember app use the same header and footer, but I direct all requests /itinerary-builder/* to the page that hosts the ember app. Ember allows you to specify what your root url is (if the SPA is not on the root URL)

There are more details in this Answer: Possible to have multiple ember.js apps in one Rails app?

Community
  • 1
  • 1
ianpetzer
  • 1,828
  • 1
  • 16
  • 21
  • Thanks! and an interesting project there ;) – luigi7up Sep 23 '14 at 12:42
  • 2
    Good answer and helpful links but I'm most excited because I was also doing some pre-planning for my next anniversary trip, which is to be a Safari in Africa, this morning. Glad you posted the Big5 links as I hadn't yet heard of the site ... SO for the win: tech help and safari planning LOL :)!! – craig.kaminsky Sep 23 '14 at 16:02
  • Its a pleasure! Get in touch through the site if you have any safari related questions. My business partner knows everything about safaris! – ianpetzer Sep 24 '14 at 18:22