2
2

J
a
n
u
a
r
y

2
0
0
6

Flash bang

Alternative title: “What happens when you’re a happy software engineer”.

One remarkable effect of having good relationships with customers is that the quality of your work improves. Let’s face it, if everything is going sour, or there’s a lot of pressure, you just want to get the job done, out of the door, then you can forget about it. If everything is ‘cool’, I work better.

Little iterations start to appear, alongside a strategy for development of each iteration, and each piece of work within each iteration becomes planned, concisely defined and exemplary. At least according to my experiences.

So for a little while yesterday and today I turned my attention to error and confirmation messages. Not because I had to, but because it was bugging me and I wanted to sort it out. A tricky problem with an easy solution.

You see, in the MVC architecture for a website we’re developing, I had the views responsible for decoding the results from the controllers and displaying the appropriate messages. This works fine, except when the same view gets invoked from different actions. Under these circumstances you need, at the very least, a switch in the view that works out what message to display. Which is just wrong. What you need is a Flash.

In Rails, a flash provides a way of passing temporary objects between actions. It’s primarily used for messages to show to the user. Let’s face it: if there’s one part of a web application that knows what confirmation to show the user, it’s got to be the actions. Views shouldn’t know anything or do anything about them.

I therefore started migrating the error messages away from the views and back into the controller actions, updating the view templates to show the flash if set. There are a number of benefits:

  • Views no longer need to concern themselves with the decoding of action results and display of messages;
  • Each controller method is now responsible for both the action and the feedback. If the action changes, feedback can be appropriately adjusted;
  • The application can now provide positive as well as negative feedback.

It will take a while to review each action and determine what flashes are required, but the overall work is minor and the result is a better website, providing better feedback to users. We end up with a happier customer.

Leave a Reply

copyright ©2006 and so on, ninthspace.org, except quotations, lyrics and some images which are the rights of their respective holders