Articles tagged “rails”
Rails3: Better, Faster, Stronger

For those who understand italian, I’ve just published an article on therubymine.com on the upcoming Ruby on Rails framework release, version 3.0: the big news is the merger with another ruby web framework, merb.
Have a nice read! :-)
http://therubymine.com/2009/06/04/rails3-better-faster-stronger/
A permalink_fu improvement: allow modification of permalinks and send HTTP redirects on-the-fly
Another spin-off from the www.visitacsa.it website: a permalink_fu improvement that allows dynamic permalinks. I know it is an oximoron, because permalinks should be .. well .. permanent! And because search engines index them, they should never change. But what happens when you publish something, your permalink is generated with permalink_fu using the title of your post, and after a couple of days you want to change the title, and the permalink under which the post is accessible as well?
Following the specification, your app should send out a 301 moved permanently HTTP status when accessing the old permalink and redirect the client to the new Uniform Resource Locator. That’s quite the same thing what my modification to permalink_fu does: whenever your post attributes are changed, the former and new permalinks are saved to the database, and you can enable your controller to generate 302 moved temporarily redirects when needed. In other words, it checks whether the requested URL is an old permalink, and automagically redirects the client to the new one.
Remove a lightwindow trigger link after an AJAX call
Well, this is the result of 2 days of head-banging with lightwindow:
Index: public/javascripts/lightwindow.js, line 444
_removeLink : function(removed) {
// remove it from the links array
//
this.links = this.links.reject(function(link) {
if (link == removed.href)
return true;
});
// remove it from the gallery links array
//
if (gallery = this._getGalleryInfo(removed.rel)) {
klass = gallery[0];
name = gallery[1];
if (this.galleries[klass] && this.galleries[klass][name]) {
this.galleries[klass][name] =
this.galleries[klass][name].reject(function(link) {
if (link == removed.href)
return true;
});
}
}
},
call this function from your .rjs template, something like this:
page << "myLightWindow._removeLink($('element').down('a.lightwindow'));"
More details to follow, when this work will be complete ;).
Active Gibberish
UPDATE: you don’t need this code, because starting from the 2.2 version of Rails, localization support is built-in.
Localization for Active Record error messages
Today i had to answer to one of the questions every non-english Rails developer stumbles upon now or after.. how to localize AR error messages for pleasant appearance to a non-english customer ;).
First off, thanks to “defunkt’s”: http://errtheblog.com excellent gibberish plugin and to the way AR validation errors are exposed, the task was accomplished in an easy and clean manner, without messing too much with AR’s internals.


