Pursuing Radical Simplicity Using Rails
I’ve been rambling about Radical Simplicity on more than one ocassion. Please go back and search for posts on that topic if you need to brush up on this concept. Today, I’m going to briefly discuss the way that Rails offers a foretaste of this principle.
If It’s Worth Displaying, Then It’s Worth Modifying
Radical simplicity is radical because it is based on the principle of radical trust. The radical trust crowd insists that whoever is using information technology deserves to be treated as an intelligent being.
So, in order to offer a radical trust type of information technology, we must leave the glass cage world of web browsers and go into the brave new world of web editors. Meaning, we must find easy and simple ways to allow users of our technology to modify what they read on the screen.
Browser Model is Broken
I became aware that the current browser model is broken the day I set the wiki for my wife’s web site. After I set it up, I showed my wife how she can now freely publish information on it.
Several hours later, my wife called me at work complaining that the wiki is not working! What? What do you mean not working, honey? Well, my wife explained, I’ve tried to change the title of one of my posts, and it wouldn’t take it.
OK, wait till I get back home, and then we’ll look into it.
Once I got home, I was astonished to see my wife clicking on the said title on her wiki, and then trying to type over it. No, honey, this is not how it works. First, you must scroll all the way down until you see this sexy little Edit button, then you must click on it, and only then will you be able to modify the title.
But, that’s very stupid, exclaimed my wife!
And come to think of it, it is. It’s very stupid. And that’s why the current browser paradigm is broken.
Web 2.0 to the Rescue!
Luckily, we now live in the 21st century, and the antiquated browser-based technology should not stop us from making headway. The best way to ride on the tailcoats of this newfangled 21st century technology is to side with Rails. At least until such time when the web editors become as ubiquitous as web browsers are today.
So how can we switch from the mere window shopping, to the full blown manipulation of the wares that are on display, using technology such as Rails? Easy. Rails comes with a built-in in place editing. That’s pretty much all we need in order to make this first step into the world of 21st century technology.
Here is how it works (in a nutshell, of course):
Suppose you have an abstraction that you call Article. This abstraction helps you host content of your articles, including the titles, categories, date of creation, etc. In your Rails controller (which controls the behavior of that abstraction) you’d then declare:
in_place_edit_for :title
This declaration should enable your application to let users modify the title right where they see it, without having to scroll down (or up) and hunt for the Edit button.
Two more things need to be handled in your application code before this ability to offer radical simplicity to your users comes to life.
In your view (that is, your template), you need to specify that the field called ‘title’ (and belonging to the ‘article’) is an in place editor field:
< %= in_place_editor_field :article, ‘title’ %>
(also, don’t forget to include pertinent javascript libraries: < %= javascript_include_tag :defaults %>)
Lastly, when the user clicks on the title and modifies it, and then clicks on ‘OK” (or hits the Enter key), you must decide how you wish to update the title. Typically, you’d declare a new capability in your controller:
def set_article_title
@article = Article.find(params[:id])
@article.update_attribute(’title’, params[:value])
end
And you’re done! It is now up to you what you’d like to display to the user after the title has been modified (like, any encouraging messages, such as great job!, or you may prefer to just quietly obey the users’ commands).
Of course, goes without saying that you can do the same ‘about face’ for all your other content — the body of the article, the tags, you name it.
There is really not much to it — it’s straightforward, easy, radically simple.