Wyświetlanie postów z 2011

Validation error objects (and hashes)

TL;DR. You can add Hash or custom class instances as error. It does not have to be a String.

Let's start with a simple Rails code that uses standard validation errors and see what kind of problems we have with such approach.

This is how it looks like when validation error occurs:

Let's just say that for a better ui experience we want to change the formatting of such
validation message (ex. numbers can be bold so that user pays attention to them). However, current solution does not allow us to do it easily. That is because of the fact that error is simply a String. Also the whole message is generated on the model side and just displayed on the view. This is a very quick and simple approach but does not give as a wide spectrum for improvement. Fortunately our errors does not to be of such simple type. We can put there something more complex like a Hash.

Looks perfect but sadly this implementation leads to I18n::InvalidPluralizationData exception so we must get a little dirty t…

Communication between controllers and views via symbol messages

Sometimes a new, simple idea allows us to see the world better and understand the limitations that previously we did not even know we have. We are all accustomed to code like this:

The problem is that sometimes we want to format the flash message. Maybe part of the text needs to be in bold. Maybe we want to display it entirely different. In such case we just need to remind ourselves that there is no need to generate and put the message into flash object in the controller. Maybe we should not generate such informational messages in controllers at all. If that action was performed by mobile device you probably would not generate the message that phone is supposed to display to the user. That does not feel right, does it? Instead, you would provide enough information so that the device can provide a meaningful message. Also, it would be the job of the phone to display it in a proper language. So, why don't we try the same approach with browsers.

And here is the final effect:

Despite the…

convert: Unrecognized option (+repage)

If you are getting "convert: Unrecognized option (+repage)" error for example from paperclip gem it probably means that you need to install imagemagick package instead of relaying on graphicsmagick-imagemagick-compat package that is in Ubuntu and provides binary named same way.

Faster rails development part 2 - Annoucing Active Reload

As you may know I have been experimenting recently with speeding up rails development mode.

In my previous post I described a solution that decreases number of code reloads by checking for changed files. However there were few caveats and the solution was definitely not beautiful and simply to apply.

I invented a second solution based on guard which initially looked promising but after using it for some time on my project I noticed that it does not work well all the time and I was not able to determine why.

Here it is in case you are curious:

I would be glad to heare some opinions about why it sometimes stops working after some time... Seriously, I have no idea.

Anyway, I decided to go third way and build "simplest thing that could possibly work"

What is it ? Instead of relaying on third party tool that can detect file changes (like watchr or guard) lets just check mtime of every file before request to check if the code needs to be reloaded or not. After all, it takes only 0.01s t…

Get faster rails development environment for Rails 3.0.7 in few seconds

I would like to describe two techniques for speeding up your Rails development environment.

Faster rendering

All credits for mentioning this goes to Eric.

This will only be helpful if your view renders lot of small partials. Ex. you render a big table and every cell is rendered by the same partial.

Faster code reloading

Rails "forgets" your code after every request so that next time the code is loaded again using autoloading. However this is totally unnecessary if you don't change the code between requests. Let's reload the code before every request if the code changes between them.

We use 'config/environments/development.rb' to execute watchr script for observing files. We only want to observer them when 'rails server' command was executed. In 'rails console' mode we use the 'reload!' command for manual code reloading.

The watchr script is going to update modification time of '.watchr' file and notify us about it if we want. You can …

The Witcher 2 - Installation error [pack3581.rra]

In case you encountered an error:: "There is not enough space on the disk." for file f:\Program Files\Wiedźmin 2\CookedPC\pack3581.rra you should know that it might mean 2 things:

there is not enough space on the disc;

you tried to install the game on FAT filesystem which does not handle such big files. Try to install the game on NTFS filesystem or convert existing one.

Wiedźmin 2 - błąd instalacji [pack3581.rra]

Jeśli w czasie Twojej instalacji Wiedźmina 2 wystąpił błąd: "Za mało miejsca na dysku" dla pliku f:\Program Files\Wiedźmin 2\CookedPC\pack3581.rra to może oznaczać, że:

faktycznie masz za mało miejsca na dysku;

próbowałeś zainstalować grę na systemie plików FAT, który nie obsługuje tak dużych plików. Zainstaluj na grę na dysku z system plików NTFS

Nested procs