If you're a rails developer you've probably tackled forms which update multiple models and have their own custom validations and/or business logic involved. I'm talking about forms like Signup which may need to create a few other models after the User has successfully been saved.
I've recently had to build a signup form which would create or organization, then create a new postgres schema for the organization, then build the administrative user model and also capture payment. Doing this with simple
after_create calls would most likely wreak havoc later in life so I've split this out into a separate
If you need to customize the field name for ActiveRecord validation messages, I wrote this quick little
include that allows you to remap column names.
For example, if you have a
User with a
name field and you didn't like the default "Name cannot be blank." message, and instead wanted "Your name cannot be blank" you can include this module and use
rename_fields :name => 'Your Name' to rename the column.
Here is a small service I wrote which will use the openweathermap.com weather service in angular.Continue Reading
Here is a small piece of code that can be dropped into an angular project and used to get the users geolocation through the browser.
The first few times I tried it I was hung up on the scope not updating, but
$rootScope.$apply seemed to get around that. Here is a JSFiddle to see how this works.
If you ever found apps like Divvy or SizeUp lacking, you should check out slate window manager. It is a free, open-source window manager for OSX that is very customizable.
A huge bonus of Slate is that it allows you to setup window layouts - specific places for specific windows. This is great for different scenarios: working, dealing with email, chatting, etc. Just setup a different layout and toggle between them when switching tasks for added productivity. The up-front cost kind of sucks, but it can be worth it.
One of the things I was struggling with was creating basic window layouts with it, and I devised a bootstrap-like grid "framework" for it. What it does is try to create a generic 12x12 grid on the screen, so you can push and pull app windows into specific coordinants, similar to how a CSS framework would do it.
The framework really just sets up some slate aliases that let you set window dimensions in a more human-friendly way. The aliases break down into 4 main categories:
When using these with slate's move command you can quickly and easily setup a window arrangement that suits your needs.Continue Reading
I was writing an API in rails a while back and as I started to write the client I noticed that, while using Devise's TokenAuthenticatable strategy, there was no other way to pass the token in besides the
This was a little odd since you would expect something like a token to be able to be passed in through the Authorization headers. I ended up writing a custom devise strategy that will now allow you to pass your user's token in via the Authorization header.Continue Reading
I don't mean to imply that git pulling and merging is painful, because it isn't. I just wanted to showcase a pretty nice gem called git-smart. You can install it using
gem install git-smart.
What this gem does is pretty simple, it attempts to do the "right" thing depending on the situation. I'll run through a few of the commands:Continue Reading
Heres a small script from Ben Hoskings which is immensely useful. It lists all the branches in your git project ordered by when you last worked on them. It also highlights branches which have not yet been merged into your current branch, which is super useful when looking to prune some branches.Continue Reading
I'm switching things up this time. This post has nothing to do with code, and everything to do with an awesome gadget. Today my nest learning thermostat came!
If you're unfamiliar with the nest, it is a replacement for your programmable thermostat that learns your habits and programs itself, among other things like monitoring energy usage to help save you money. If that isn't cool enough, it is wi-fi enabled which means it auto-updates itself, I can set the schedule from a website, and I can control the temperature in the house from anywhere in the world. Is it lame to get so excited about a thermostat? Probably, but who cares, this thing is fucking cool. Check it out.Continue Reading