Posts for: #Rails

Released Sashimi 0.2.1

I’ve just released a new version of Sashimi (0.2.1), it fixes a bug for Ubuntu.

The Problem

When the script starts tries to load repository concerned classes: GitRepository and SvnRepository, which are subclasses of AbstractRepository. In repositories.rb I use Dir#[] to load all the .rb files in a certain directory, but the order of the resulting array is unpredictable, so if the first class was not AbstractRepository Sashimi was crashing.

The Solution

I’ve fixed it, so, if you have experienced this problem, please update Sashimi with:
$ (sudo) gem update sashimi

[]

Cached Models

cached_models provides to your models a transparent approach to use Rails internal cache mechanism.

Usually, when you decide to use cache for your ActiveRecord results, you have to manually implement complex expiring policies. cached_models simplifies your code:
class Author true end

class Post true end

That’s all!!.

A more complex example..
class Project true

has_many :tickets, :cached => true has_many :recent_tickets, :limit => 5, :order => ‘id DESC’, :cached => true end

[]

Ruby Time marshaling bug in pre-1.9

Ruby’s Time has a bug: when try to serialize an timezoned time, then unserialize it back, the result will use the server local time, instead of use the original time zone.
>> utc = Time.now.utc => Fri Aug 29 09:07:37 UTC 2008 >> marshaled = Marshal.dump utc => "\004\bu:\tTime\r\251\037\e\200\344\254T\036" >> Marshal.load marshaled => Fri Aug 29 11:07:37 +0200 2008

This bug doesn’t affects Ruby 1.9, but we still don’t use that version for production purpose. If you use 1.8.x with Rails 2.1.0, your cached timestamps (including ActiveRecord objects), are probably wrong.
>> comment = Comment.first => #<Comment id: 865423346, post_id: 1, text: "Nice post.", created_at: "2008-08-29 09:27:48", updated_at: "2008-08-29 09:27:48"> >> Rails.cache.write('comment', comment) => true >> Rails.cache.read('comment') => #<Comment id: 865423346, post_id: 1, text: "Nice post.", created_at: "2008-08-29 09:27:48", updated_at: "2008-08-29 09:27:48"> >> comment.update_attributes :text => "Nice post!" => true >> Rails.cache.write('comment', comment) => true >> Rails.cache.read('comment') => #<Comment id: 865423346, post_id: 1, text: "Nice post!", created_at: "2008-08-29 09:27:48", updated_at: "2008-08-29 11:28:42">

Look at the last updated_at attribute, it uses local time instead of UTC time zone.
The first time everything goes right, because #updated_at wasn’t invoked and casted to a Time instance. It’s a string, and the marshaling is ok.
But, when I update the object, ActiveRecord changes the value of that timestamp, but before, it cast it to a Time, and everything goes wrong.

[]

Click To Globalize: Ready for Rails 2.1!

Click to Globalize is ready for Rails 2.1!

I spent a lot of time to make this release the best of ever! I know that a lot of time has passed since the latest Rails major release, and I apologize for this. The official Globalize it seems dead, but the great work of Nate Clark (aka heythisisnate) has made it compatible with Rails 2.1. Thanks Nate! The Rails Edge now includes a basic support for i18n!

[]