How can I change the column name from the db so it''s displayed in view in a different way? -- Posted via http://www.ruby-forum.com/.
Pål Bergström wrote:> How can I change the column name from the db so it''s displayed in view > in a different way?Your question is unclear as stated. Can you provide more context? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser wrote:> Pål Bergström wrote:> Your question is unclear as stated. Can you provide more context? > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.orgThe column name in the db is ''email''. I would like that to be displayed in Swedish like ''E-post''. -- Posted via http://www.ruby-forum.com/.
Pål Bergström wrote: [...]> The column name in the db is ''email''. I would like that to be displayed > in Swedish like ''E-post''.And what''s your view file like? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser wrote:> Pål Bergström wrote: > [...] >> The column name in the db is ''email''. I would like that to be displayed >> in Swedish like ''E-post''. > > And what''s your view file like? > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.orgI mean in an error_messages_for. Sorry. -- Posted via http://www.ruby-forum.com/.
Are you using Rails 2.2 or 2.3? In these versions, you could use the I18n library (editing the .yml on the config/locales directory): activerecord: attributes: <model_name>: <field>: <translated_name> On Oct 16, 6:31 pm, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Marnen Laibow-Koser wrote: > > Pål Bergström wrote: > > [...] > >> The column name in the db is ''email''. I would like that to be displayed > >> in Swedish like ''E-post''. > > > And what''s your view file like? > > > Best, > > -- > > Marnen Laibow-Koser > >http://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > I mean in an error_messages_for. Sorry. > -- > Posted viahttp://www.ruby-forum.com/.
You could put this in your model (the one that maps to the table with the email column) if you don''t need to use the internationalisation capabilities: HUMAN_ATTRIBUTES = {:email => ''E-post''} def self.human_attribute_name(attr) HUMAN_ATTRIBUTES[attr.to_sym] || super end Note that you can rename more than one column: HUMAN_ATTRIBUTES = {:email => ''E-post'', :some_other_column => ''Another name''} On Oct 17, 10:31 am, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Marnen Laibow-Koser wrote: > > Pål Bergström wrote: > > [...] > >> The column name in the db is ''email''. I would like that to be displayed > >> in Swedish like ''E-post''. > > > And what''s your view file like? > > > Best, > > -- > > Marnen Laibow-Koser > >http://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > I mean in an error_messages_for. Sorry. > -- > Posted viahttp://www.ruby-forum.com/.
Chris Bartlett wrote:> HUMAN_ATTRIBUTES = {:email => ''E-post''} > def self.human_attribute_name(attr) > HUMAN_ATTRIBUTES[attr.to_sym] || super > end > > > Note that you can rename more than one column: > HUMAN_ATTRIBUTES = {:email => ''E-post'', :some_other_column => ''Another > name''}Great. Works perfect. -- Posted via http://www.ruby-forum.com/.