Disclaimer gem

I was chatting with a colleague who has asked me to build an app, and I was struggling to get to the root of what he wanted. After the chat, I had a little think about the problem, and realised that a lot of what was required could be dealt with by adding a disclaimer. That is, redirecting a user to a page that described things the user needed to be aware of before they got to their destination page, and to which they would have to acknowledge. The result was my latest gem ‘disclaimer‘.

I wanted it to behave like a before_filter, so the easiest way to do that was to use a before_filter under the bonnet. I also wanted to allow for the use of multiple disclaimer documents, so different destinations could have different disclaimers. So the system takes the name of the disclaimer to be displayed. The result allows you to do this in a controller:

disclaimer :organisation_disclaimer, :except => [:index]

The before_filter hook in was the bit that took the most head scratching, and the result was adding some methods to ActionController::Base.

I used an engine to provide the functionality, and that allowed me to easily add controllers to build disclaimer documents.

For my current requirement, I needed to break the document down into segments, so I added a model and controllers to do this. I also wanted the segments to be displayed via a JQuery accordion. I think in the long term, I’ll remove this, and just have a simple document controller. Developers will then be able to over-ride the simple document as they need.

I think I’ll also want to add some configuration options to the disclaimer, but I’m leaving adding them until I need them and therefore have a better idea of how they should behave.

One thing I will do soon, will be to add a default behaviour: so if you just add ‘disclaimer’ to a controller, it will display the first or a default disclaimer. If the latter, I’ll need to add a way of configuring this. I also need to add an elegant way of catching when a disclaimer call points to a document that doesn’t exist.

This entry was posted in Ruby. Bookmark the permalink.