Categories
Uncategorized

Rails Deficiences

There’s been quite a lot of criticism of Rails recently:

But the fact of the matter is that Rails gets so much right, that it’s still worth using. And I intend to.

Not only that, but I have every confidence that these issues will be addressed. In my case, I can see from the tickets that the whole area of database defaults is being revamped for Rails 1.1, so I’ll probably end up upgrading shortly after it comes out.

I’m reminded of the furore about the Google Web Accelerator last year. In that case, Rails was clearly in the wrong, and I said as much back then (although not fingering rails, apparently). In the end, a moderately sensible comprimise was reached: You can supply a :post parameter to the link_to command, in order to try and ensure that something gets submitted via post. It’s not perfect, as it relies on JavaScript to work, but it goes a good way to making it easier for people who don’t care to do the right thing.

In summary, Rails ain’t perfect, but it’s getting better all the time. And the way to speed it up? Patches Welcome.

Categories
Uncategorized

Typo Times Fix

After a bit of searching, I’ve found the problems with the odd times on this weblog. It’s a problem with ActiveRecord (part of Rails) and in particular, PostgreSQLAdaptor.

Basically, it computes a default value once, inside Ruby, and then caches it. Which is a bit odd, to say the least.

There are a number of open tickets related to this: 2873, 2877, 2257 and probably more. But looking at them, it seems that the problem will be fixed in Rails 1.1, which should be released “soon”.

Meanwhile, I’ll patch this particular instance of Typo to update the time on create. This is what I’ve used, and it seems to be working ok.

Index: app/models/article.rb
===================================================================
--- app/models/article.rb       (revision 727)
+++ app/models/article.rb       (working copy)
@@ -94,6 +94,9 @@
     self.extended_html = HtmlEngine.transform(extended, self.text_filter)
   end

+  # Work around PostgreSQL adaptor (http://dev.rubyonrails.org/ticket/2873)
+  before_create { |art| art.created_at = Time.now }
+
   def self.time_delta(year, month = nil, day = nil)
     from = Time.mktime(year, month || 1, day || 1)

Index: app/models/comment.rb
===================================================================
--- app/models/comment.rb       (revision 727)
+++ app/models/comment.rb       (working copy)
@@ -29,4 +29,7 @@
     self.body_html = HtmlEngine.transform(body, config["comment_text_filter"], [:filter_html])
   end

+  # Work around PostgreSQL adaptor (http://dev.rubyonrails.org/ticket/2873)
+  before_create { |art| art.created_at = Time.now }
+
 end