August 5
Posted by mtoledo
Filed under rails, ruby |
There’s a caveat when using rails optimistic locking inside callbacks in a fault tolerant way with mysql’s default settings. Of course that’s a lot of things and sounds like a very specific scenario, but its not that much. Let me break it down:
Rails optimistic locking
Rails will automatically create locks around a record being updated in [...]
July 1
Posted by mtoledo
Filed under rails, ruby |
I’ve recently found out a very odd particularity about how ActiveRecord behaves when relationship properties through the update_attributes method in ActiveRecord::Base. In fact due to its simple implementation, its actually a behavior of any saving of relationships on dirty records.
# in rails ActiveRecord::Base (base.rb)
# Updates all the attributes from the passed-in Hash and saves the [...]
May 21
Posted by mtoledo
Filed under javascript, ruby |
For a couple of days I’ve been trying to implement a scriptaculous’ InPlaceEditor on one of my pet project’s scriptaculous’ Sortable list.
First I had no luck with the easy to find InPlaceEditor rails helpers that you easily find on google: The traditional in_place_editing plugin required controller changes and didn’t support rest too well. Nakajima’s “better_edit_in_place” [...]
April 14
Posted by mtoledo
Filed under ruby |
Raganwald has written a very elaborate piece about his “objection to Array#sum“. Since I patircularly like Array#sum, I thought I might weight in on my own blog.
First, I think that his piece has 2 different objections:
1) Array shouldn’t return true for a “responds_to? :sum” call if it has contents that can’t be summed ( like [...]
April 9
Posted by mtoledo
Filed under ruby |
Ruby has a pretty expressive and flexible case statement. It actually differs from most other language’s ’switch’ statements in that it auto-breaks on each condition instead of falling through.
// C
switch (x) {
case 1:
doSomething();
break;
case 2:
doSomethingElse();
break;
}
# ruby
case x
when 1: do_something
when 2: do_something_else
end
I do think not having to break was the right decision, but not everyone agrees and [...]
April 8
Posted by mtoledo
Filed under ruby |
Ruby is a very powerful language, and the methods available to manipulate its 2 main data structures, Array and Hash, are really good. Though, some of them are really obscure, and for some other manipulations you are on your own. This happens specially with the Hash class.
To me, this is probably because although both Array [...]