One more question: Is there some way to set the human_name of a column? e.g.: human_name for column address1 shouldn''t be Address1 but "Address, line 1". If not, should I make a hash with my custom names? Best regards, -- ---------------------------------------------------------------------- Yannick Majoros http://www.inma.ucl.ac.be/~majoros Informaticien UCL/INMA-MEMA 4, avenue G. Lema?tre B-1348 Louvain-la-Neuve Belgium Tel: +32-10-47.80.10 Fax: +32-10-47.21.80 Si vous avez des probl?mes pour afficher ce message (accents qui ne passent pas, signature ?lectronique, ...) votre syst?me de mail n''est pas conforme aux standards modernes, voir http://www.inma.ucl.ac.be/~majoros/email.html #JAPH : http://www.inma.ucl.ac.be/~majoros/japh.txt ---------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3403 bytes Desc: S/MIME Cryptographic Signature Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060601/2f006bbf/smime.bin
ActiveRecord uses the humanize method from the Inflector module in ActiveSupport to convert column names to human readable form. (See http://rails.outertrack.com/module/Inflector/humanize) You can potentially override this method something like this: module Inflector def humanize_with_fixes(name) case name when ''address1'' ''Address line 1'' else humanize_without_fixes(name) end end alias_method :humanize_without_fixes, :humanize alias_method :humanize, :humanize_with_fixes end I''m not sure if this is the recommended approach, but it should work. It might be easier to just rename your column to address_line_1! (Note that ActiveRecord also has a human_attribute_name method you could override for the same purpose, but source code comments indicate that this method is deprecated and that ActiveRecord may call the Inflector directly.) Cheers, Pete Yandell http://9cays.com/ On 01/06/2006, at 11:28 PM, Yannick Majoros wrote:> One more question: > > Is there some way to set the human_name of a column? e.g.: > human_name for column address1 shouldn''t be Address1 but "Address, > line 1". > > If not, should I make a hash with my custom names? > > Best regards, > > -- > ---------------------------------------------------------------------- > Yannick Majoros http://www.inma.ucl.ac.be/~majoros > Informaticien UCL/INMA-MEMA > 4, avenue G. Lema?tre > B-1348 Louvain-la-Neuve > Belgium > Tel: +32-10-47.80.10 > Fax: +32-10-47.21.80 > Si vous avez des probl?mes pour afficher ce message (accents qui ne > passent pas, signature ?lectronique, ...) votre syst?me de mail > n''est pas conforme aux standards modernes, voir > http://www.inma.ucl.ac.be/~majoros/email.html > #JAPH : http://www.inma.ucl.ac.be/~majoros/japh.txt > ---------------------------------------------------------------------- > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> You can potentially override this method something like thisThat seems slightly icky, (where is that code going to go?) but I can''t think of anything better at present. How are these custom names going to be used? But also! You can change this alias_method :humanize_without_fixes, :humanize alias_method :humanize, :humanize_with_fixes to this alias_method_chain :humanize, :fixes as shown here http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails- module-alias_method_chain -- Michael Daines http://www.mdaines.com
On 02/06/2006, at 1:03 PM, Michael Daines wrote:>> You can potentially override this method something like this > > That seems slightly icky, (where is that code going to go?) but I > can''t think of anything better at present.I never said it was a nice solution. :)> But also! You can change this > > alias_method :humanize_without_fixes, :humanize > alias_method :humanize, :humanize_with_fixes > > to this > > alias_method_chain :humanize, :fixes > > as shown here > > http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails- > module-alias_method_chainNice. I hadn''t come across that before. Cheers, Pete Yandell http://9cays.com