Angular with Rails - Fixing XHR

TLDR Get request.xhr? to work with Rails and Angular's $http service by adding the following code to your Angular app: angular.module('myModule').config ['$httpProvider', ($httpProvider) -> $httpProvider.defaults.headers.common.['X-Requested-With'] = 'AngularXMLHttpRequest' ] Rails and Angular are hard to get to work with each other. There's just…

Read this article

Using SQL Views in Rails

As applications grow and your data get more complex, SQL views become incredibly useful tools to easily access large queries. SQL views also come with some caching benefits that you can't get from writing long queries directly into your application code. The problem with SQL views, is that ActiveRecord doesn't…

Read this article

Making options dependant on other options with Thor

In a recent project of mine, I had to build a CLI on top of my RubyGem with Thor. Part of the gem required the user to either pass a directory or a bucket to the command, which had both --directory and --bucket options. Initially I just raised StandardError both…

Read this article

Playing with Foundation SASS in your Layouts

Have you ever wanted to create a layout with Foundation without all those column and row divs? Take a look at this HTML: <main> <article> ... </article> <aside> ... </aside> </main> That's all the HTML you'll need to create a…

Read this article

Fixing nested rows in Foundation

For as long as I can remember Foundation has had a bit of a problem where nested rows end up with margins on the left and the right. If you're using SASS to develop with Foundation the fix is really easy. In app.scss just add the following line to…

Read this article

Using Default Values in Ruby Hashes

I was recently faced with a task to accomplish in a Ruby project that I'm working on: Create a hash of arrays and a method to add new keys to the hash as well as new values to the arrays. My first go at the issue resulted in something like…

Read this article