July 2008 Archives

Just a mockup you say?

| | Comments (0) | TrackBacks (0)

Recently, one of our customers wanted to have a mockup of an application. We thought at first to use Rails to make this mockup, but suddenly we realize that it was overkilling to create models and controllers when the requirements are not clear enough.

Once we decided not to use Rails to do this task, we did study some Ruby CMS around the Web. The different options we came around were:

  • Pro
    It offers a lot of neat features like partials, layouts, host configurations and the most outstanding: custom view helpers.
    Con
    It just limited to Haml & Sass templates, so you will need to know this template system in order to use it.
  • Pro
    Is one of the biggest Ruby CMS around on the Web, it offers a lot of features like partials, layouts, templates, filters, tasks, etc.
    Con
    IMHO, is just to big for the average mockup site, if you will use this to make a mockup, you probably would like to stick with rails.
  • Pro
    It offers the same options as many other CMS (partials, layouts, filters).
    Con
    The configuration is not as comfortable as in other CMS.
  • Pro
    It offers the same options as many other CMS (partials, layouts, filters), but also, it provides helpers for rendering LaTeX and Graphviz content, offers the chance to make custom rake tasks, offers CodeRay and Ultraviolet support for code highlighting on the mockup. The configuration is pretty easy, and it offers auto generation on file changes.
    Con
    It does not offer the custom view helpers feature and the docs are not as big as you would like.

As you may guess, I went to the option of Webby, it seems the more middle-size CMS made in Ruby that offers a lot of options and is easy to configure.

If you want to provide more observations on the comments section, is highly appreciated, I did not make a deep study on the others CMS, so maybe I'm missing some pros on each of them.

Recently I'm testing in Firefox 3 the "admin" section - implemented using ActiveScaffold - of a Rails application we made.

I'm getting RJS Errors when trying to update a record:
  • TypeError: $$("#admin__operator_details-update-151-form a.cancel").first().link is undefined
  • $$("#admin__operator_details-update-151-form a.cancel").first().link.close_with_refresh();

The issues is already reported as #553

The summary is that the problem lies within the deprecated getElementsByClassName function in the active_scaffold.js.

To fix (thanks to Eric Bjorkvall) just replace in files:

  • /public/javascripts/active_scaffold/default/active_scaffold.js
  • /vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js
the line: with:

Instead of replacing the original assets of ActiveScaffold I skipped the change on /vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js and just comment the /vendor/plugins/active_scaffold/init.rb in order to avoid the copy assets on plugin initialization.

View Tips to avoid Growing Pains

| | Comments (0) | TrackBacks (0)

Finally it comes the time when (even if you avoided at all costs) you must develop the view part of the project. Here I'll summarize some of my experiences in Tips that you should keep in mind before start coding like a monkey.

Reorganize your view structure if the project doesn't follow the Rails golden path

A lot of people tries at all costs to adapt their code to the Rails organization, that shouldn't be always the case.

There will be times when you will have a same partial, shared in more than one controller. This normally causes some questions about why the partial is in this controller and not in the other, the simple answer to that question would be: "the partial is in the controller X because it was the first one who used it".

In this cases, you should keep a shared folder inside the views folder, this way you'll know that the partial doesn't belong to any controller at all, is just a shared view between lot's of controllers. If you notice that your shared folder is starting to get fat, organize partials that have common purposes in sub-folders, this way you won't be lost when looking for a shared partial with a particular purpose.

Then, when rendering a partial, you would do something like

Here we have shared partials that are being used in the header sections of lot's of controllers. This way you keep an order in your views that is more comfortable and more understandable.

In your partials, use helpers as much as you can

When you have partials, is probably because you repeat the same view in a lot of places. The thing is that you normally would like the partials to behave differently in some cases, say you want the URL's of the partials of a profile to point somewhere else or not to point anywhere at all (when you have a public profile for example). In this cases the best thing you can do is use helpers for returning the URL's.

You shouldn't bother with lots of if's and else's when the sweet polymorphism can do the job quite easy, just overwrite the method in the controller's helper and the partial will behave differently on each controller it is called1.

So for example, Imagine we have a profile section, and you have 2 versions of this profile, the public version, and the private version. This versions have a lot of things in common in the view side, but when we are in public profile, all the links points to a link of a public section, while when on private profile, the links point to private sections.

The view on the partial (shared/header/month.html.erb) would be something like

Now, when we are on the public controller, the helper should behave like

And on the private controller, the helper should behave like

Here we are letting the polymorphism of the helpers solve the view repetition, by just providing a method that behaves differently depending on where we are standing.

Parametrize... ALWAYS

Programmers are lazy, and there is nothing wrong with that, but sometimes this laziness can give us some nasty moments, it all starts with: "why pass it as a parameter? Just access it via the current_user, or the @instance_variable and you won't have to pass parameters every time you invoke this helper/partial".

This will give you more problems than benefits at the end, just imagine what would happen if the helper method/partial would work for every user we would like to, but it only calls the current_user?. This is when refactoring comes along and we change the current_user for a parametrized user, the thing is that you call this refactored method like 150 times. There is when you say... "damn, it would be easier if I just passed the user as a parameter from the beginning". Always keep in mind that the more you use your global environment, the less reusable is your code.

Don't to use instance variables in the partials (change them with the :locals option), nor to use instance variables on the helper modules if they are not being used only in the module for private logic (pass the objects as parameters to the functions).

I hope this 3 tips can help you get a better start when coding views.




  1. You have to keep in mind that this probably won't work in recent versions of Rails unless you comment the inclusion of all the helpers in all the views (I wouldn't recommend this feature if you want your views to be scalable).

Welcome aboard

| | Comments (0) | TrackBacks (0)
Well, finally a blog. We decided (flip of coin, you know) that having a few paragraphs of static content and call it "the company web site" was so boring, and useless that we were going to completly drop it, and focus in the blog.

Anyway, there is "page" called Everything you wanted to know before hiring us just in case you have heard about us and you are considering to do so.

We are supposed to keep this site updated with great content, so please feel to bookmark it or better add the feed to

About this Archive

This page is an archive of entries from July 2008 listed from newest to oldest.

August 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.