validates_presence_of :fname results in the error message "Fname can''t be blank". What I want is "First Name can''t be blank". I could do this def validate errors.add_to_base("First Name can''t be blank") if fname.blank? end I find this clunky and I have to put everyrhing in the validate method. Is there an easy to get what I want. I tried this also validates_presence_of :fname , :message => ''new message'' still retains the fname. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060808/1cb8f73b/attachment-0001.html
Assuming that you are using error_messages_for, why don''t you try overloading it to work the way you want. I would think that''s the easiest thing to do. -carl On Aug 8, 2006, at 4:11 PM, Neeraj Kumar wrote:> validates_presence_of :fname > > results in the error message > > "Fname can''t be blank". > > What I want is "First Name can''t be blank". > > I could do this > > def validate > errors.add_to_base ("First Name can''t be blank") if fname.blank? > end > > I find this clunky and I have to put everyrhing in the validate > method. Is there an easy to get what I want. > > I tried this also validates_presence_of :fname , :message => ''new > message'' still retains the fname. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I could try overloadin it but that causes the detachment issue. For example if I have column name "fname" and I want the message to appear as ''First name" then in the "error_messages_for" method I need to put the code to replace ''fname" by "First name". Ideally I would like somethign like this. validates_presence_of :fname, :show_attribute_name => ''First name''. Already we have a feature like validates_presence_of :fname , :message => ''new message'' . I guess I need to learn more ruby (& rails) in order to do this kind of hack. If someone already knows how to accomplish it easily please let me know. -=- On 8/13/06, Carl Lerche <carl.lerche@verizon.net> wrote:> > Assuming that you are using error_messages_for, why don''t you try > overloading it to work the way you want. I would think that''s the > easiest thing to do. > > -carl > > > On Aug 8, 2006, at 4:11 PM, Neeraj Kumar wrote: > > > validates_presence_of :fname > > > > results in the error message > > > > "Fname can''t be blank". > > > > What I want is "First Name can''t be blank". > > > > I could do this > > > > def validate > > errors.add_to_base ("First Name can''t be blank") if fname.blank? > > end > > > > I find this clunky and I have to put everyrhing in the validate > > method. Is there an easy to get what I want. > > > > I tried this also validates_presence_of :fname , :message => ''new > > message'' still retains the fname. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/5d105e46/attachment.html
Hi, How about Ruby-GetText-Package? It''s an library for internationalization. But I think it''s fit for your purpose. http://www.yotabanana.com/hiki/?ruby-gettext-howto-rails On Tue, 15 Aug 2006 10:47:48 -0400 "Neeraj Kumar" <neeraj.jsr@gmail.com> wrote:> I could try overloadin it but that causes the detachment issue. > > For example if I have column name "fname" and I want the message to appear > as ''First name" then in the "error_messages_for" method I need to put the > code to replace ''fname" by "First name". > > Ideally I would like somethign like this. > > validates_presence_of :fname, :show_attribute_name => ''First name''. > > Already we have a feature like validates_presence_of :fname , :message => > ''new message'' . I guess I need to learn more ruby (& rails) in order to do > this kind of hack. If someone already knows how to accomplish it easily > please let me know. > > -=- > > > > > > On 8/13/06, Carl Lerche <carl.lerche@verizon.net> wrote: > > > > Assuming that you are using error_messages_for, why don''t you try > > overloading it to work the way you want. I would think that''s the > > easiest thing to do. > > > > -carl > > > > > > On Aug 8, 2006, at 4:11 PM, Neeraj Kumar wrote: > > > > > validates_presence_of :fname > > > > > > results in the error message > > > > > > "Fname can''t be blank". > > > > > > What I want is "First Name can''t be blank". > > > > > > I could do this > > > > > > def validate > > > errors.add_to_base ("First Name can''t be blank") if fname.blank? > > > end > > > > > > I find this clunky and I have to put everyrhing in the validate > > > method. Is there an easy to get what I want. > > > > > > I tried this also validates_presence_of :fname , :message => ''new > > > message'' still retains the fname. > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- -- .:% Masao Mutoh<mutoh@highway.ne.jp>
On 8/8/06, Neeraj Kumar <neeraj.jsr@gmail.com> wrote:> validates_presence_of :fname > > results in the error message > > "Fname can''t be blank". > > What I want is "First Name can''t be blank". > > I could do this > > def validate > errors.add_to_base ("First Name can''t be blank") if fname.blank? > end > > I find this clunky and I have to put everyrhing in the validate method. Is > there an easy to get what I want. > > I tried this also validates_presence_of :fname , :message => ''new message'' > still retains the fname.I''ve always wondered this too. :-(
I use the following to give me more flexibility with error messages: http://rubyforge.org/projects/custom-err-msg/ works perfectly Mike On 8/15/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> On 8/8/06, Neeraj Kumar <neeraj.jsr@gmail.com> wrote: > > validates_presence_of :fname > > > > results in the error message > > > > "Fname can''t be blank". > > > > What I want is "First Name can''t be blank". > > > > I could do this > > > > def validate > > errors.add_to_base ("First Name can''t be blank") if fname.blank? > > end > > > > I find this clunky and I have to put everyrhing in the validate method. Is > > there an easy to get what I want. > > > > I tried this also validates_presence_of :fname , :message => ''new message'' > > still retains the fname. > > I''ve always wondered this too. :-( > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I use the plugin customm-err-msg. It allows you to omit the attribute name, but then you have to provide the whole message like validates_presence_of :fname, :message => "^ First Name can''t be blank" Dirk Neeraj Kumar wrote:> validates_presence_of :fname > > results in the error message > > "Fname can''t be blank". > > What I want is "First Name can''t be blank". > > I could do this > > def validate > errors.add_to_base("First Name can''t be blank") if fname.blank? > end > > I find this clunky and I have to put everyrhing in the validate method. Is > there an easy to get what I want. > > I tried this also validates_presence_of :fname , :message => ''new message'' > still retains the fname.