Writing Rails-flavored AngularJS
When I think about Ruby on Rails and AngularJS in the same codebase, I kind of cringe. After spending more than a year trying to reconcile how Rails plays with Angular, not only have I been unsuccessful, but I have not been satisfied with any of the suggested solutions. There is a ton of material on the numerous Rails hacks you should employ so that Rails and AngularJS feel compatible; however, I’m beginning to wonder whether this problem is being approached from the wrong direction. Instead, how can we hack AngularJS so that it plays nice with Rails?
Two-way binding works right out of the box with Sprinkles. Wrapping objects
bindable controller helper gives them the
And then in the view, you can either bind to the entire JSONified object with
or just a single attribute with an argument.
We’ll take this a step further by creating a directive to make our name blink very rapidly (obviously). Let’s first write the directive.
And now we can include the directive in our view with the
BOOM! Annoying blinking tag!
Finally, it’s very important to be able to still use Angular’s built-in event
bindings. For example, clicking a button and showing an alert box. Sprinkles
solves this by allowing developers to inline Angular services with the
And then in the view,
Let us know what you think
Angular Sprinkles is a new approach to Angular-Rails development. It’s for those of us that love both of these great technologies and want to see them work together pleasantly. Please have a look at the gem for more information on setup and leave some feedback. We would love to know what you think.