Archive

Archive for December, 2007

autotest keeps running continuosly even without changing any files?

December 21st, 2007 Dante Regis No comments

So, your autotest also keeps running over and over when your Rails code fails? Well, I had this issue here and found that the problem was that, when the tests were run, Ferret updated the index. So, autotest believed that files where changed when they weren’t. Googling a bit I found this code that you should put on your ~/.autotest :

Autotest.add_hook :run do |at|
  at.exceptions = /^(?:\.\/)?(?:db|index|doc|log|public|script|tmp|filestore|vendor\/rails)|\.svn|(?:.*_flymake\.rb$)/
end

If it does not work, try running autotest with “-v” option, to see which files have changed on autotest concern, and include the relevant directory on the list above.

Hope this helps you! :)

Categories: rails, ruby Tags:

Custom Humanize Column Names in Ruby on Rails

December 10th, 2007 Dante Regis 3 comments

Henrik, from The Pug Automatic, suggested a great way of having custom column names on the rails validation error messages, by rewriting the human_attribute_name of ActiveRecord. There’s an example on his blog (really worth a look and not only for this specific post) on how to do that. Beware that it uses a deprecated method of ActiveRecord, that may be removed in future versions of Rails (it is still there on Rails 2.0). The workaround is discussed there too on the comments: One could rewrite the humanize method of String – that would make changes global – or we can just ask politely for the core developers not to remove the method :) .

Here is an example of how to do that, I used it on an application of mine. On this case, the collumns on the database are in english, which I prefer working with when programming , but the users can barely read Portuguese, so I need to translate to them:

class Ticket < ActiveRecord::Base
  HUMANIZED_ATTRIBUTES = {
    :description => "Descrição",
    :category => "Categoria",
    :title => "Assunto"
  }

  def self.human_attribute_name(attr)
    HUMANIZED_ATTRIBUTES(attr.to_sym) || super
  end
end
Categories: Uncategorized Tags: