Rails Error Messages For Plugin
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting custom error messages rails ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
Unknown Validator: 'messagevalidator'
the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Fully custom validation error message with Rails up vote 191 down vote favorite 108 Using Rails I'm trying to get an error message like "The song field can't be empty" on save. Doing the following: validates_presence_of :song_rep_xyz, :message => "can't be empty" ... only displays "Song Rep XYW can't be empty", which is not good because the title of the field is not user friendly. How can I change the title of the field itself ? I could change the actual name of the field in the database, but I have multiple "song" fields and I do need to have specific field names. I don't want to hack around rails' validation process and I feel there should be a way of fixing that. ruby-on-rails share|improve this question edited Jun 14 '10 at 10:08 asked Apr 30 '09 at 19:05 marcgg 33.9k39153210 add a comment| 10 Answers 10 active oldest votes up vote 334 down vote accepted Now, the accepted way to set the humanized names and custom error messages is to use locales. # config/locales/en.yml en: activerecord: attributes: user: email: "E-mail address" errors: models: user: attributes: email: blank: "is required" Now the humanized name and the presence validation message for the "email" attribute have been changed. Validation messages can be set for a specific model+attribute, model, attribute, or globally. share|improve this answer edited Oct 17 '12 at 16:30 answered May 18 '10 at 16:43 graywh 6,30021923 16 If you are using mongoid, replace activerecord: with mongoid: –Intentss Nov 6 '11 at 14:07 83 @graywh: Where should questions about an answer be posted, if not in the comments? Here's the I18n guide: guides.rubyonrails.org/i18n.html –Tyler Rick Dec 15 '11 at 20:45 4 By the way: if you pass a symbol in for the message parameter of your validator in Rails 3.1.3, it will tell you the scope it was looking for as it won't e found, so you know exactly what to put in your locales yml. –aceofspades Feb 14 '12 at 5:46 3 Well, this is fine and all, but what if naively prepending the column name (no matter how human readable it is) would lead to completely f-uped grammar (
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails Join them; it only takes a minute: Sign up How can I use customer error messages on form fields generated by Ruby on Rails when using the jQuery validation plugin? up vote 1 down vote favorite I'm trying to use jQuery Validation plugin with customer error messages in a form on my site. The way to specify customer http://stackoverflow.com/questions/4105939/how-can-i-use-customer-error-messages-on-form-fields-generated-by-ruby-on-rails messages is as follows: $('#user_new').validate({ messages: { user_email: { required: "dd ", email: "Please enter a valid email address, example: you@yourdomain.com" } } }); This will apply the custom error messages to the input with the name of user_email. This code works okay. The problem is that the fields have names such as user[email] because they are generated by Rails using form_for. But this won't work: $('#user_new').validate({ messages: { user[email]: { required: "dd ", email: "Please enter a valid email address, example: you@yourdomain.com" } } }); The user[email] part causes a javascript error. Has anyone got custom messages working on Rails generated input fields with this plugin? Thanks for reading. jquery ruby-on-rails jquery-plugins validation jquery-validate share|improve this question asked Nov 5 '10 at 12:45 ben 7,9052695154 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted Have you tried just quoting the javascript array keys? messages: { "user[email]": { required: "dd ", email: "Please enter a valid email address, example: you@yourdomain.com" } share|improve this answer answered Nov 5
- October 6, 2011 (6.5 KB) 1.1.0.pre3 - https://rubygems.org/gems/custom_error_message/versions/1.1.1 December 20, 2010 (6.5 KB) 1.1.0.pre2 - December 17, 2010 (6.5 KB) 1.1.0.pre - December 12, 2009 (5 KB) 1.0.0 - December 12, 2009 (5 KB) Authors: David Easley, Jeremy Durham Owners: SHA 256 checksum: f8a129456c6563148a322a625575403428b834fc818134ba77786916f49a8fce ← Previous version Total downloads 66,663 For error messages this version 57,537 Gemfile: = Copy to clipboard Copied! install: = Licenses: N/A Required Ruby Version: None Links: Homepage Download Documentation Badge Subscribe RSS Report Abuse Status Uptime Code Data Discuss Stats Blog About Help API Security RubyGems.org is the Ruby community’s gem rails error messages hosting service. Instantly publish your gems and then install them. Use the API find out more about available gems. Become a contributor and improve the site yourself. RubyGems.org is made possible by many sponsors, with development funded by the Ruby trade association, Ruby Together. Members get access to exclusive benefits and offers from partners (like Hired, empowering developers on the hunt for a job). We need your help to keep RubyGems.org running smoothly and free for everyone to use. Join Ruby Together today. Supported by Ruby Central Supported by Ruby Together Designed by DockYard Resolved with DNSimple Optimized by New Relic Tracking by Gauges Monitored by Runscope Gems served by Fastly Logging by Logit Tested by Travis CI English Nederlands 简体中文 正體中文 Português do Brasil Français Español Deutsch