kishanio
kishanio

Reputation: 7079

Intergrating Angular JS with rails

I need some guidance to figure out how to incorporate Angular inside rails.

Reason for choosing Rails : I like their opionated approach to do things right. Also migrations, gems are really cool.

Reason for angular : I was researching and looking for framework best suited for SPA. Backbone seem too abstract. I had choice to make between Angular & Ember. I started reading Angular first and it made sense to me. So i never went to read about ember.

Reason for Angular & Rails: I researched and tried using small scale framework like grape, slim ( Yes i use php too ). But i feel need to stick to rails for long term scope of project. And personally i like doing things rails way.

So here is where i need help,

I have rails project in Rails 4.

Sign-in , sign-up everything is created as followed in Michael Hartl tutorial. Have tweaked stuff based on my requirement.

So post-sign-in or post-sign-up steps a view from show action of users controller is rendered.

I figured i'll need different layout files so i created same for outer pages and inner pages, respectively.

I don't know how to proceed i want to make use of the angular templates and routes for my single page app ( which resides post sign-in ). I am flexible if there is another way. I just need a guide how to use angular seemlessly with rails making use of rails controller to handle my rest request and using routing provided by angular to navigate around in SPA.

Hope i am clear. Feel free to edit this.

Upvotes: 6

Views: 3366

Answers (5)

zacatac
zacatac

Reputation: 69

I'd suggest taking a look at this tutorial: How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application. I have used it for a few personal projects, so I am sure that it is up to date as of late 2014. If you want to view it in action you can head to http://goodmatches.herokuapp.com, and you can view the repo.

Upvotes: 1

helcim
helcim

Reputation: 819

Try half-pipe gem which makes using bower for managing javascripts assets much easier.

Upvotes: 0

venkatareddy
venkatareddy

Reputation: 775

I would suggest you to not mix angular into your rails app. Keep both of them separate.

So you could either place the whole of your angular app in the public folder of your rails app or keep it completely away from the rails app. This is more like a service oriented architecture, where your rails app serves as a back end serving as an api and the front end(Angular app) consuming that api.

There are many many nice articles the covers how to handle the authentication/authorization in angularjs with REST APIs.Authentication with AngularJS and a Node.js REST api

Coming to the rails side for building REST API, Grape is a nice choice. Here is a nice series explaining some best practices about grape.

HTH!

Upvotes: 1

PaulL
PaulL

Reputation: 6650

I'm not familiar with SPA, but I have been working on a tutorial for integrating rails and angularjs, which I'm refining over time. It may provide some answers here - in particular I am using the angular routing to provide a single-page app as you describe: http://technpol.wordpress.com/2013/09/03/angularjs-and-rails-tutorial-index/

Upvotes: 1

Rodrigo Zurek
Rodrigo Zurek

Reputation: 4575

here is a great railscasts from ryan bates: http://railscasts.com/episodes/405-angularjs

also here is the source for that railscasts you can get ideas from there:

https://github.com/railscasts/405-angularjs

Upvotes: 1

Related Questions