282 RR Angular on Rails with Jason Swett
Charles: Hey everybody and welcome to episode 282 of the Ruby Rogues podcast, this week on our panel we have a new Rogue, Jerome Hardaway.
Jerome: Hi everybody, calling live from San Francisco with General Assembly and Dream Force. Really happy to be having this opportunity and be able to connect with the Rogues out there.
Charles: Awesome. We also have a special guest this week and that’s Jason Swett.
Charles: I think I forgot to introduce myself. I’m Charles Max Wood from Devchat.tv. This week we’re gonna be talking about Angular on Rails. Jason, do you wanna give us a brief introduction to yourself and then I will get started talking about Angular and Rails.
Jason: Sure. My name is Jason Swett, I’m the author of the angularonrails.com, I’m historically a Rails’ developer, I’m teaching myself Angular over the last little while and as I’ve been teaching myself Angular, I’ve been teaching it to other people as well.
Charles: Nice. I think Jerome you also mentioned that you’ve done some Angular.
Jerome: Yes. I actually used Angular and Rails to teach better in style of code. I used to work a lot in using Angular and Rails for the past couple of years. That definitely is a great front end connector for your Rails app. I love it.
Charles: Awesome. I’m curious, is your experience mostly with Angular 2.0 which has been out for I think three weeks now or is it Angular 1.0?
Jerome: For me or the guest?
Charles: For both of you.
Jerome: Angular 1.0 for me, 1.0 or 1.5 I guess I could say, I haven’t really dived into Angular 2.0 yet. I don’t know Swett, is your tutorial, is that Angular 2.0 now?
Jason: Yes. It’s Angular 2.0. Pretty much, all of my production and Angular experience is Angular 1.x. almost everything that I’m doing, going forward with angularinrails.com is Angular 2.0 because I figured, for the people who are just coming into it, they’re gonna mostly invest their time and to learn Angular 2.0. Angular 1.0 is definitely not going away at any time soon. I wanna have some kind of balance but of stuff I’ve been doing lately is Angular 2.0.
Charles: Alright. I think we’re all familiar with Angular but let’s assume that or listener is familiar let’s say with Rails but not with Angular. Why would somebody want look in this something like Angular, why not just do things the Rails way.
Jason: Good question. I actually think that, in a lot of cases, you should just use Rails and you don’t have to use front end framework like Angular in all cases. I’ll kinda describe the cases in which you might want to.
As you do that, you have so many Ajax requests and so much front end logic and stuff like that and it’s very easy to let that run away from you and end up with a huge amount of Spaghetti code.
In my mind, one of the benefits of Angular is that it gives you places to put things and it gives you some structure for your front end portion of your application so that you don’t automatically end up with a mess. You can still end up with a mess even if you do use Angular but it gives you slots to put things. That’s one part of it and the other part of it is just it makes all this interactivity a lot easier than if you’re coding all the stuff from scratch.
Jerome: Roger that. I was gonna actually piggyback on that. One of main reasons that I’ve been using Angular on Rails is for a more dynamic webplus. As you see, the interactivity on the web has like you said exploded and what was a novelty is now come the expected by the end user.
Live information, data modelling just come into front end and that’s one of my main reasons why I use Angular. I was a little intrigued on if you were ever going to expand on that Angular tutorials for users. Are you coming out with a book or anything in that regard?
Jason: Well before I answer that, expanding which part exactly do you mean?
Jerome: Expand on more the real time data modelling that you can do with Angular when it comes to information and actually having it show or search like a fuzzy search, things with that nature. Are you gonna be implementing more of that into your tutorials?
Jason: Good question. That kind of stuff is more detailed than the stuff I’ve been covering so far. What I’ve been covering so far is just the super, most basic stuff like how do I even set up an Angular Rails app at all.
That’s actually really not a straightforward question and answer you know because there’s a number of different ways you can do it and a lot of different decisions you have to make.
When it was Angular 1.0 and I was building my first Angular in Rails app, this is like 2013 or 2014 that I was getting started with that combination. I was like, “Okay, how do I structure my Angular application? Where do I put stuff?”
I don’t think at that time we had what now was I think was thede facto standard, now I think it’s officially blessed as the standard that John Papa Angular Style Guide. That didn’t exist or at least I didn’t know about it back then. Everybody just kinda structured their Angular application, however their dev team decided to. There’s really no direction.
That was one thing and then it’s like, “Okay, do I structure this as like a client server architecture where Rails is just purely an API and then I have the client side like maybe even in a separate repo or do I put Angular in the asset pipe?” There’s so many decisions you have to make just before you even get to square one and you can have a hello world app.
That was one of the first things that I documented. I think what I ended up choosing was, and I don’t do it this way anymore, but what I used was Gulp with Yeoman. Yeoman was kind of the key component to the way I was spinning up my Angular 1.0 apps because they have a command that you could run and generate in Angular app.
It would give you a directory structure and to me that was great because a lot of people who comes from a Rails’ background have the philosophy of like, “I want the framework to be opinionated and to make most of the decisions for me. I want there to be one right way to do stuff even if I might not necessarily agree with the one right way to do stuff. At least everybody’s doing it the same way.”One of the really nice things about Rails is that if you jumped into any Rails project, chances are that it’s gonna pretty much look like most of