Angular JS integration with rails

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

Reason for choosing Rails: I like that their intoxicating approach does everything right. Also migrations, gems are really cool.

Reason for Angular: I studied and searched for the framework that is most suitable for SPA. The highway seems too abstract. I had a choice to make between Angular and Ember. At first I started reading Angular, and that made sense to me. So I never read about ember.

Reason for Angular and Rails: I researched and tried using small frames like grapes, slim (Yes, I also use php). But I feel the need to stick to the rails for the long-term scope of the project. And personally, I like to do things with rails.

So this is where I need help

I have rails in Rails 4.

Login, registration, everything is created in accordance with the instructions of Michael Hartle. Changed the settings based on my requirement.

Thus, after the steps after login or after registration, the visual action of the user controller is displayed.

I realized that I needed different layout files, so I created them for external pages and internal pages, respectively.

I do not know how to proceed. I want to use Angular templates and routes for my one-page application (which is located after login). I am flexible if there is another way. I just need guidance on how to use Angular without visible problems using rails using the rails controller to process my rest request and use the routing provided by Angular to navigate the SPA.

I hope I understand. Feel free to edit this.

+6
source share
5 answers

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

There is also a source for these railscasts, which you can get from there:

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

+1
source

I am not familiar with SPA, but I worked on a tutorial on the integration of rails and corners, which I improve over time. Some answers may be presented here - in particular, I use angular routing to provide a one-page application that you describe: http://technpol.wordpress.com/2013/09/03/angularjs-and-rails-tutorial-index/

+1
source

I suggest you not mix angular in your rails application. Keep them apart.

This way, you can place your entire angular application in the shared folder of your rails application or completely remove it from the rails application. It is more like a service-oriented architecture where your rails application serves as the back end acting as an api and front end (Angular app) consuming this api.

There are many many interesting articles on how to handle authentication / authorization in angularjs with the REST API. Authentication with AngularJS and Node.js REST api

Coming to the side of the rails to create the REST API, Grape is a great choice. Here is a nice series explaining some best practices about grapes.

NTN!

+1
source

I would suggest taking a look at this tutorial: how to enable Ruby on Rails and AngularJS as a one-page application > . I used it for several personal projects, so I'm sure it has been updated to the end of 2014. If you want to view it in action, you can go to http://goodmatches.herokuapp.com and you can view the repo .

+1
source

Try the half-pipe gem, which greatly simplifies the use of bower to manage javascripts assets.

0
source

Source: https://habr.com/ru/post/951404/


All Articles