Archive for the ‘ruby on rails’ Category

Rails localisation bug


2009
08.20

I’ve just gone through the challenge of working out what was wrong with the following piece of code:

<% form_tag :controller => '/' do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

Our client reported that on a signup page where they choose an alternative language it got redirected and they could never reach the page in their native language.

How can this happen you might ask?

Well the request includes some values within the url which are used as a key. Only if the key is valid is the controller allowed to complete the request. The issue is the combining of maintaining the key and switching the language.

As it happens its a very simple fix and was pointed out to me by Juliana.

<% form_tag :controller => request.request_uri do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

In this fixed second example the alteration for the controller has been updated to direct the language selector to the controller of the current page. The documentation for this suggests that its broken on IIS (really should you be even trying to use this?) in fact I found that the source has had a significant amount of work go into it to work around the issue and even make it work on that webserver. Its a great little solution to ensure that the reloaded page is returned to the user in the state it was with the addition of the correct language.

Rails – if I new when I started what I know now?


2009
07.18

How would you answer this question?

I’ve been using rails for development of applications for what feels like a long time. I wasn’t in the pre 1.0 crowd but I did spend many days hacking around in cgi scripts to make the website run in apache so I do feel like I’ve been here a while.

As brackground I came up through C++ operating systems development (loved it), delphi (blah blah), then on to Java (which I never liked) and into web technologies and scripted languages.

My day job doesn’t allow more than 10-20% of development anymore (by choice). So although I’m still keen the time is not usually available. Interesting this has quite an impact on way you program.

For one thing change is an issue, changing technology requires great investment just to achieve the simplest of tasks. Something I can not afford.

Rails has always been for me about using a good language to enjoy my craft. For a variety of reasons enjoyment does enable better results. Further the rails stack goes all the way through the systems I need to utilise – database, ORM, MVC, and client side (javascript + tempaltes). By understanding one language and leveraging the well written information on Rails I avoid needing to care about most other areas.

However the trade off is that sometimes it just can’t do what you need so some custom javascript or SQL query is required. I’ve never been particularly strong at either. So that usually gets less of my attention. I break the rules at this point and do what needs to be done to get the job done. Many in the community would disagree with this approach. And I applaude them, they are correct but realities/needs/timescales differ. As yet I’ve never had a hard time sleeping at night!

In many cases the Agile method of working is excellent. I was slow to value the testing framework built into the system. For a while I played with Selenium (amazing solution) but I have a regularly changing interface and could never get beyond the issue that tests broke because they were out of date (not the application was broken). Shoulda on the other hand has been very helpful as has rcov.

Of course the testing approach when time constrained is brief in some aspects. And not by design. Its just their is no documentation on how to achieve certain things – e.g. validate a upload dialog can import, parse and process an zip file + manifest. Of course this is domain specific but validation of file uploads is not, and as yet I’ve not found anything on this.

Google is a strong friend when there is trouble. I’ve found many articles and blogs to guide me. Although sometimes in the wrong direction – engines. There coming back and I’m scared I found them confused and difficult the first time around so I wonder (without a name change) who will be listening?

Would I do it all again: yes. In fact I’d do more. Its a fantastic stable platform which has I believe shaken up the entire ‘intelligent’ web development community along with its cousins DJango I’m looking at you. I’m sure that even in these difficult times we’ll continue to see this is a fertile ground with many innovations and improvements yet to come.

Looking to the future I’m very aware of the tiny amount of knowledge I have. I’ve spoken to many in the community who are streets ahead. I wonder if I’ll ever get to where they are? Do I need to perhaps not, if anything I can say that even with a small amount of knowledge and clear understanding of the principles (which you can pick up very quickly) creating the next application is available to almost any developer.

If only rails could create cross platform desktop applications?


Localising a rails app – in 20 mins


2009
02.07

I had an existing rails app which has nearly completed and during its development its been upgraded from 1.2 all the way up to 2.2.2. Anyway I sat down with the latest updates and figured that acts_as_paranoid and will_paginate needed to be altered but beyond that it seems it just worked.
Suffice to say I’d managed to configure the locales and make heavy use of google translate to begin adding an alternative language.
It is impressive how easily this has come together.