Scott Watermasysk

Still Learning

Adding a WYSIWYG Editor to ActiveAdmin

ActiveAdmin is a nice way to quickly build admin pages. Think of it as a scaffolding on steriods. It is probably not ideal for most customers, but you can accomplish quite a bit with minimal effort.

One of the models I was editing with ActiveAdmin accepts HTML in a textarea. I find the thought of writing even a single angle bracket nauseating these days, so I decided to convert the editor into a WYSIWYG editor with TinyMCE.

ActiveAdmin is a rails engine which plugs directly into your existing app. It provides a nifty little DSL for building UI screens. Getting the editor to work took just a couple of minutes once you understand the basic pieces.

KickoffLabs Is Ready for You!

Today is the official launch day of KickoffLabs.

Today KickoffLabs is officially live and accepting customers! Scott and I want to thank everyone who signed up on our own KickoffLabs “coming soon” page, shared our blog posts and tweets, helped us kick the tires on the private beta, and sent encouraging words along the way. Thank You! KickoffLabs is Open for Business!

There are a lot of interesting lessons and observations to share over the next week or two, but for now, I am going to just take a deep breath and watch for all of your account confirmation signup emails. :)

Running Pow Over SSL

We are just about ready to put KickoffLabs into production mode. One of the last big tasks was setting up SSL.

Obviously, do not we want to push SSL support live without first testing it, so I set out to set it up locally.

I considered a variety of approaches and eventually settled on using Pow with nginx as a reverse proxy.

Clicking on a DIV With Capybara

For the record, I am not sure this is a good practice. In fact, I am pretty for for accessibility it is probably the not the best solution…but for now this is how it works.

The scenario:

When selecting a theme in KickoffLabs we allow a user to simply click on a preview image which is wrapped in a div. This executes a bit of javascript and properly stores the selected id so it can be sent to the server and stored in the database. In an earlier version this was simply a select element which Capybara has a simple built in method for (select). Once this was changed to a div (or image) the spec broke.

Thankfully, the fix is quite simple, just use find (which returns an element) and execute click.

1
find("#Energy_Blue").click

Also, since this is executing javascript, it requires the use of the javascript driver.

Why iTerm2 Is Dope

I tried iTerm2 about a year ago (or so) and didn’t get it. Obviously, I wasn’t trying very hard. I gave it another shot a couple of weeks ago and it has been pure love.

Here are 5 really simple things that I love about it:

Better Rails 3 Logging Output

I added two gems to my Gemfile today which dramatically improved my local development log output.

  1. Itslog - The formatting will prepend all log statements with a colored header and additional information about the statement. The information and structure of the new statements is customizable through configuration.
  2. Silent-Postres - Silences internal diagnostic messages from postgresql connection adapter.

The only gotcha I had after adding these gems is I needed to switch to the dark iTerm2 solarized theme to view the Itslog output (although this can be overridden if I really want to use the light background).

Highly recommended.

Simple Resque Mail Queue - II

Here is a slightly cleaned up version of the simple Mail Queue for resque I published a couple of weeks ago.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module MailQueue
  extend self

  def queue
    :default
  end

  def perform(options = {})
    options = options.with_indifferent_access

    mailer = options[:klass].constantize
    method = options[:method]
    mailer.send(method, *options[:args]).deliver
  end

  def enqueue()
    EnqueueProxy.new(self)
  end

  class EnqueueProxy

    def initialize(klass)
      @klass = klass
    end

    def method_missing(m, *args, &block)
      if @klass.respond_to? m
        options = {:klass => @klass.to_s, :method => m, :args => args}
        Resque.enqueue(MailQueue, options)
      else
        super
      end
    end

  end

end

The biggest change is the options are now all stored in a simple hash with keys for the class, method, and extra arguments. The previous version should continue to work, but if you grabbed this code, I recommend updating to this version since it should be easier to maintain (and debug if necessary) in the future.

Git Flow

This post should serve as my own quick start guide for Git Flow.

Git extensions to provide high-level repository operations for Vincent Driessen’s branching model.

Here is all you need to know:

First, start here: Why aren’t you using git-flow?

Then install via: brew install git-flow (read the docs on git-flow github for how to install on other platforms)

Finally, some helpful git short cuts:

fs = flow feature start
ff = flow feature finish

With these short cuts in place, you can use git-flow for new features like this:

git fs login
git ff login

Loose Associations in ActiveRecord

First the scenario:

I have two tables/models which are loosely related. What I mean by loosely is they share column (email), but they can exist without each other. What I wanted to do is bring back the data for each without causing an N+1 set of queries.

Here is the basic design: