acts_as_versioned

Developing with Ruby on Rails is wonderful. I had been dreading implementing versioned objects, which are needed if I want to introduce publicly editable fields. But after a bit of googling I found the acts_as_versioned plugin that does it all for you in one line of code!

Amazing!

class Page < ActiveRecord::Base
  acts_as_versioned
end

The acts_as_versioned at the top of the model class is all that’s needed. It’s so simple it makes you wonder what the catch is, except there is no catch.

Test your rails helpers

This evening I tried to get my test coverage up a bit by making tests of the helper classes using Geoffrey Grosenbach’s Test Your Helpers instructions. But I couldn’t get it to work. Has anyone used it? Does it work? Or is there some other way?

Testing the helpers is the last big thing left to get to the unreachable 100% test coverage. So naturally I want to solve it!

If you can’t get RJS to work

It might be because you, like me, have put the following in application.rb:

    before_filter :set_content_type
    def set_content_type
            @headers["Content-Type"] = "text/html; charset=utf-8"
    end

Change that to:

    before_filter :set_content_type
    def set_content_type
        if request.xhr?
          @headers["Content-Type"] = "text/javascript; charset=utf-8"
        else
          @headers["Content-Type"] = "text/html; charset=utf-8"
        end
    end

And your RJS magic will start to work!

RJS?

If you like me have seen people mentioning RJS but not understood what it is, Cody Fauser has a good introduction which will make it all crystal clear.