Using Mono on the PhidgetSBC2

So this Monday my PhidgetSBC2 arrived and I was super excited to get started playing around with the short-term goal of being able to open my door lock remotely.

I really wanted to write the code in C# because it's simply better than Java and it's lot easier to implement a server in C# than in C. While the manual for the SBC2 says you can get Mono working if you install the correct packages, I couldn't find any information on the Phidget website on how to do it, so I had to figure it out myself.

Continue reading "Using Mono on the PhidgetSBC2"

Simple Rails Multi-Tenancy

With some recent commits to rails comes the ability to have a default_scope with a lambda that gets evaluated at query time. Combine that with a multi-tenant column scoped database structure (wow, quite the mouthful) and you've got an quick and painless way to partition your tenant data without scattering code everywhere.

Continue reading "Simple Rails Multi-Tenancy"

Playing with FormBuilder

The methods that come with the standard ActionPack::Helpers::FormBuilder cover most cases of what you need to do but if you need to do something it doesn't have a method for, things can get a little ugly.

In my case I wanted to create a helper for autocompleted fields that all had the same attributes but different arguments (the urls).

So let's say you have an Unobtrusive JavaScript file that looks for an attribute called data-autocomplete, normally when you wanted to have the field autocompleted, you would pass in the attribute to the form helper text_field.

f.text_field :username, :'data-autocomplete' => users_path(:json)

While there is nothing bad about doing this, you end with a bunch of :'data-autocomplete' scattered about in your views which makes it harder to change down the road if you were to switch your JS implementation.

A nicer way is to have your own form builder method called autocomplete_field which requires two arguments (method and url) that adds the :'data-autocomplete' option (which is now in one place and easily changed) for you. Best part is this can be done with only one helper file.

Continue reading "Playing with FormBuilder"