Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Aidid Jaafar
PLUS
Aidid Jaafar
Courses Plus Student 4,354 Points

HELP: Angular.js and Rails

First of all, this is my first post. I am not well aware if there is any rule before posting out. I wanted to know how can I use Angular.js as a client side MVC and combine it with Rails.

Upon using Google and few hours research on stackoverflow I find some interesting way, but still in the dark, I hope to get some pointers and reading materials on the implementation.

Thank you for reading, have a great Monday everyone.

4 Answers

gary lucas
gary lucas
989 Points

I have some experience with Angular, none with Rails.

Angular is an opinionated JS / MVC client framework.

Rails is?

Basically my understanding of how to use Angular goes like this:

  • Build out your one page web app using fake repository implementations. ** Build it out using either the included / recomended testing framework (Testacular and Jasmine). Do NOT skimp on tests, the only good reason to use a client sided MVC framework is the ability to get your UI code under test. Take the time to do so.
  • When your good on the client side and want to start integrating server side the best option is to make use of a restfull API (Angular includes components to help with this). ** Implement your API calls as repository components.

Now, I think the point of this post is that Angular is a client sided JS framework, the server side doesn't matter from that point onwards.

http://stackoverflow.com/questions/11106631/angular-js-integration-with-ruby-on-rails-forms

I've integrated Angular with MVC.net and the .NET side was just a couple of routes that exposed restfull API services.

That is probably the most effective way to use the two in conjunction, I did a bit of reading on rails and I'm pretty sure trying to use both client side will run into many issues. I'm sure you could jury rig something together but you'd probably need to be very, very experienced in one or both frameworks.

Good luck

Chuck Lauer Vose
Chuck Lauer Vose
3,191 Points

Rails is really good at providing a JSON api which things like AngularJS and Backbone can use for data persistence. In backbone, Model.sync will request JSON from some server, which in this case could be done with Rails or Sinatra or even with just a .json file on a server somewhere.

Here's a video: http://vimeo.com/30328747

You can use a rails plugin to get AngularJS included into the asset pipeline, or you can just put the angular files in app/assets.

I hope that's helpful!

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Great answers, all! If you're a Gold member, be sure to check out Jim's Workshop on AngularJS.

Here's the link for Jim's Workshop called Building with AngularJS and APIs