Luiz Vitor Martinez Cardoso
2008-Jul-19 15:28 UTC
How to alias the columns names to change the name on error_messages_for ?
Yeah, How can i alias the columns names to show another string name in error_messages_for? class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :pizza, :string I want to show ''salame'' Thanks for your attention! -- Regards, Luiz Vitor Martinez Cardoso cel.: (11) 8187-8662 blog: rubz.org engineer student at maua.br --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz
2008-Jul-19 16:32 UTC
Re: How to alias the columns names to change the name on error_messages_for ?
This is what I have done in the past, but it may not be the best solution. In your user model.... class User < ActiveRecord::Base def beautifunction { :pizza => ''salame'' } end def self.human_attribute_name(s) beautifunction[s.to_sym] || super(s) end end Best regards. Anna Lissa On Sat, Jul 19, 2008 at 8:28 AM, Luiz Vitor Martinez Cardoso < grabber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yeah, > > How can i alias the columns names to show another string name in > error_messages_for? > > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > t.column :pizza, :string > > I want to show ''salame'' > > Thanks for your attention! > > -- > Regards, > > Luiz Vitor Martinez Cardoso > cel.: (11) 8187-8662 > blog: rubz.org > engineer student at maua.br > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz
2008-Jul-19 17:59 UTC
Re: How to alias the columns names to change the name on error_messages_for ?
one correction to my solution: use self.beautifunction (should be a class method not an instance method) -- Anna Lissa On Sat, Jul 19, 2008 at 9:32 AM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is what I have done in the past, but it may not be the best solution. > In your user model.... > > class User < ActiveRecord::Base > > def beautifunction > { :pizza => ''salame'' } > end > > def self.human_attribute_name(s) > beautifunction[s.to_sym] || super(s) > end > > end > > Best regards. > Anna Lissa > > > On Sat, Jul 19, 2008 at 8:28 AM, Luiz Vitor Martinez Cardoso < > grabber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Yeah, >> >> How can i alias the columns names to show another string name in >> error_messages_for? >> >> class CreateUsers < ActiveRecord::Migration >> def self.up >> create_table :users do |t| >> t.column :pizza, :string >> >> I want to show ''salame'' >> >> Thanks for your attention! >> >> -- >> Regards, >> >> Luiz Vitor Martinez Cardoso >> cel.: (11) 8187-8662 >> blog: rubz.org >> engineer student at maua.br >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Luiz Vitor Martinez Cardoso
2008-Jul-19 18:11 UTC
Re: How to alias the columns names to change the name on error_messages_for ?
Thanks! This really works. But what''s the Rails way? Regards, Luiz Vitor On Sat, Jul 19, 2008 at 2:59 PM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> one correction to my solution: > > use self.beautifunction (should be a class method not an instance method) > > -- Anna Lissa > > > On Sat, Jul 19, 2008 at 9:32 AM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> This is what I have done in the past, but it may not be the best >> solution. In your user model.... >> >> class User < ActiveRecord::Base >> >> def beautifunction >> { :pizza => ''salame'' } >> end >> >> def self.human_attribute_name(s) >> beautifunction[s.to_sym] || super(s) >> end >> >> end >> >> Best regards. >> Anna Lissa >> >> >> On Sat, Jul 19, 2008 at 8:28 AM, Luiz Vitor Martinez Cardoso < >> grabber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Yeah, >>> >>> How can i alias the columns names to show another string name in >>> error_messages_for? >>> >>> class CreateUsers < ActiveRecord::Migration >>> def self.up >>> create_table :users do |t| >>> t.column :pizza, :string >>> >>> I want to show ''salame'' >>> >>> Thanks for your attention! >>> >>> -- >>> Regards, >>> >>> Luiz Vitor Martinez Cardoso >>> cel.: (11) 8187-8662 >>> blog: rubz.org >>> engineer student at maua.br >>> >>> >>> >> > > > >-- Regards, Luiz Vitor Martinez Cardoso cel.: (11) 8187-8662 blog: rubz.org engineer student at maua.br --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz
2008-Jul-19 19:50 UTC
Re: How to alias the columns names to change the name on error_messages_for ?
That''s a good question. As far as I can tell, there is no Rails way to do this as of Rails 2.0.2. I spent some time reviewing how error_messages_for works and then came up with this solution. I would love to know if 2.1 addresses the problem, or if we''re really looking at a documentation problem. Regards, Anna Lissa On Sat, Jul 19, 2008 at 11:11 AM, Luiz Vitor Martinez Cardoso < grabber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks! This really works. But what''s the Rails way? > > Regards, > Luiz Vitor > > > On Sat, Jul 19, 2008 at 2:59 PM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> one correction to my solution: >> >> use self.beautifunction (should be a class method not an instance method) >> >> -- Anna Lissa >> >> >> On Sat, Jul 19, 2008 at 9:32 AM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> >>> This is what I have done in the past, but it may not be the best >>> solution. In your user model.... >>> >>> class User < ActiveRecord::Base >>> >>> def beautifunction >>> { :pizza => ''salame'' } >>> end >>> >>> def self.human_attribute_name(s) >>> beautifunction[s.to_sym] || super(s) >>> end >>> >>> end >>> >>> Best regards. >>> Anna Lissa >>> >>> >>> On Sat, Jul 19, 2008 at 8:28 AM, Luiz Vitor Martinez Cardoso < >>> grabber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Yeah, >>>> >>>> How can i alias the columns names to show another string name in >>>> error_messages_for? >>>> >>>> class CreateUsers < ActiveRecord::Migration >>>> def self.up >>>> create_table :users do |t| >>>> t.column :pizza, :string >>>> >>>> I want to show ''salame'' >>>> >>>> Thanks for your attention! >>>> >>>> -- >>>> Regards, >>>> >>>> Luiz Vitor Martinez Cardoso >>>> cel.: (11) 8187-8662 >>>> blog: rubz.org >>>> engineer student at maua.br >>>> >>>> >>>> >>> >> >> >> > > > -- > Regards, > > Luiz Vitor Martinez Cardoso > cel.: (11) 8187-8662 > blog: rubz.org > engineer student at maua.br > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew France
2008-Jul-20 12:49 UTC
Re: How to alias the columns names to change the name on error_messages_for ?
On Jul 19, 8:50 pm, "AnnaLissa Cruz" <annalis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s a good question. As far as I can tell, there is no Rails way to do > this as of Rails 2.0.2. I spent some time reviewing how error_messages_for > works and then came up with this solution. I would love to know if 2.1 > addresses the problem, or if we''re really looking at a documentation > problem.I use the Human Attribute Override plugin (http:// agilewebdevelopment.com/plugins/human_attribute_override) with Rails 2.0 which essentially does the same thing as your earlier example. Just committed this month is a patch (http://rails.lighthouseapp.com/ projects/8994/tickets/535-humanize-inflections) that allows you to specify particular results for the humanize string method. I think it''s a flawed approach because it is not unreasonable to have the same attribute name on different models but to want different display names and I as far as I can see it will not allow that. Best regards, Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---