Update no. 2 in my quest for Rails and AngularJS fun

Chris Stehm
WorkoutApp
Published in
2 min readOct 7, 2017

Having moved quite a bit further in the development of my little workout app I have realized that I quite like the freedom that Angular on top of Rails has given me. I am able to do some fun things like pull multiple resources into a view without having to nest them, and the instant update ability that Angular gives me is nice, if not frustrating the rest of the time.

I will say that I ran into huge road blocks with routing. I could not, for the life of me, wrap my head around how I was going to get all the routing working. It just wasn’t clicking. I ended up trying a couple different solutions before settling on Angular-Rails-Resource gem. I was using the built in $http previously, and having no luck getting it to do what I wanted to I moved onto the dependency ngResource, that is part of Angular itself, but you have to inject it.

After some trial and error, mostly error, with that I found an easier way in the Angular-Rails-Resource gem. It does basically the same things, but for some reason it just clicked, and finally work was getting done. One nice thing that it does is that it allows me to just define the base route that all the Rails routes will build off of. Then I can just build the requests inside an angular controller to control what I want to happen. This frees me up from having to write a factory that controls all the routing, and patching it together manually with the controller in a way that seems like to many steps.

This has, of course, not been without its troubles, but they are more manageable now that I am able to understand it a bit better. My latest bane has been trying to get things to update without the user refreshing the screen. I could, simply, just tell angular to refresh the page, but that defeats some of the purpose of using Angular with Rails since you could easily just do the same thing with naked Rails. So that’s basically where I stand in my current development. I am getting close to a full working model, and I am moving on to getting the actual “engine” of this beast working so that it can spit out some workouts!

--

--

Chris Stehm
WorkoutApp

I am an artist, musician, developer, engineer, and learner of life!