|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Issues Customizing ActiveRecord Error MessagesI have two issues with trying to customize error messages. I'm using Rails 2.3.4 and Ruby 1.8.7. The first issue has to do with basic error message interpolation. As an example, I modified my en.yml file and added the following: en: activerecord: errors: messages: blank: "Please fill in your {{attribute}}" I have a simple model with a validates_presence_of :name When I submit a form without filling out name, the error message shows as "Name Please fill in your Name" What am I doing wrong that causes "Name" to show up twice? I feel like I am missing something basic, but looking at the Rails I18n API (http://guides.rubyonrails.org/i18n.html) hasn't helped. The second issue has to do with validations for nested attributes. In my en.yml, I have the following which provides a value for human_name on the class. (I removed the activerecord: errors: messages: blank: code for this example.) en: activerecord: models: adhoc_filter: "Filter" In my adhoc_filter child model, I have a validates_presence_of :field When I submit the form, the error message shows up as "Adhoc filters field can't be blank" instead of "Filter field can't be blank" I'm not sure if nested attribute errors will work the way I want them to, but it would be nice. Any advice on one or both of these issues is greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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@... To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Issues Customizing ActiveRecord Error MessagesAs a follow up to the second issue, if I specify the error message as: en: activerecord: errors: messages: blank: "-- {{attribute}} - {{model}}" I see the following error: "Adhoc filters fields -- Adhoc filters field -- Filter" So the model human name is getting set correctly, but the child attribute is getting concatenated with the non human-name of the model with the child field. On Nov 4, 5:01 pm, "E. Litwin" <elit...@...> wrote: > I have two issues with trying to customize error messages. I'm using > Rails 2.3.4 and Ruby 1.8.7. > > The first issue has to do with basic error message interpolation. > As an example, I modified my en.yml file and added the following: > > en: > activerecord: > errors: > messages: > blank: "Please fill in your {{attribute}}" > > I have a simple model with a validates_presence_of :name > > When I submit a form without filling out name, the error message shows > as "Name Please fill in your Name" > What am I doing wrong that causes "Name" to show up twice? > I feel like I am missing something basic, but looking at the Rails > I18n API (http://guides.rubyonrails.org/i18n.html) hasn't helped. > > The second issue has to do with validations for nested attributes. > > In my en.yml, I have the following which provides a value for > human_name on the class. (I removed the activerecord: errors: > messages: blank: code for this example.) > > en: > activerecord: > models: > adhoc_filter: "Filter" > > In my adhoc_filter child model, I have a validates_presence_of :field > > When I submit the form, the error message shows up as "Adhoc filters > field can't be blank" instead of "Filter field can't be blank" > > I'm not sure if nested attribute errors will work the way I want them > to, but it would be nice. > > Any advice on one or both of these issues is greatly appreciated. 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@... To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |