Hi How do I supress the reporting of a field name in the full error message? I want the error to be associated with the field so that the .fieldWithErrors class is applied to the field but I don''t want it to add the field name to the actual error message. For example: errors.add("occurs_on", "The date can''t be today!") unless occurs_on != Date.today I would like the error to read: The date can''t be today! Rather than: Occurs on The date can''t be today! Is there any way to do this? Thanks in advance Dave
Wilson Bilkovich
2006-Apr-22 21:26 UTC
[Rails] How to supress field name in error message?
On 4/22/06, Dave Verwer <dave@dvhome.co.uk> wrote:> Hi > > How do I supress the reporting of a field name in the full error > message? I want the error to be associated with the field so that the > .fieldWithErrors class is applied to the field but I don''t want it to > add the field name to the actual error message. > > For example: > > errors.add("occurs_on", "The date can''t be today!") unless occurs_on > != Date.today > > I would like the error to read: > > The date can''t be today! > > Rather than: > > Occurs on The date can''t be today! > > Is there any way to do this? >If you don''t care about the highlighting part, you can use errors.add_to_base. Otherwise, you may want to check this out: http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors
Thanks Wilson I do want to keep it specific to the fields so that they highlight, the link mentioned in the article you referenced: http://wiki.rubyonrails.com/rails/pages/Custom+Error+Message This seems like about the solution I was looking for, however I am not sure how to install it? It comes with an init.rb file and a lib folder with one rb file in it. I have put the init.rb in my project root and the other file into my lib folder but it doesnt seem to override the class. Anyone any ideas? On 4/22/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:> On 4/22/06, Dave Verwer <dave@dvhome.co.uk> wrote: > > Hi > > > > How do I supress the reporting of a field name in the full error > > message? I want the error to be associated with the field so that the > > .fieldWithErrors class is applied to the field but I don''t want it to > > add the field name to the actual error message. > > > > For example: > > > > errors.add("occurs_on", "The date can''t be today!") unless occurs_on > > != Date.today > > > > I would like the error to read: > > > > The date can''t be today! > > > > Rather than: > > > > Occurs on The date can''t be today! > > > > Is there any way to do this? > > > > If you don''t care about the highlighting part, you can use errors.add_to_base. > Otherwise, you may want to check this out: > http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Wilson Bilkovich
2006-Apr-23 22:37 UTC
[Rails] How to supress field name in error message?
That''s a Rails ''plugin'', so you need to extract it into the vendor/plugins/ folder under your Rails project root. There are some brief instructions at the bottom of the page: http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors On 4/23/06, Dave Verwer <dave@dvhome.co.uk> wrote:> Thanks Wilson > > I do want to keep it specific to the fields so that they highlight, > the link mentioned in the article you referenced: > http://wiki.rubyonrails.com/rails/pages/Custom+Error+Message > > This seems like about the solution I was looking for, however I am not > sure how to install it? It comes with an init.rb file and a lib folder > with one rb file in it. I have put the init.rb in my project root and > the other file into my lib folder but it doesnt seem to override the > class. > > Anyone any ideas? > > > On 4/22/06, Wilson Bilkovich <wilsonb@gmail.com> wrote: > > On 4/22/06, Dave Verwer <dave@dvhome.co.uk> wrote: > > > Hi > > > > > > How do I supress the reporting of a field name in the full error > > > message? I want the error to be associated with the field so that the > > > .fieldWithErrors class is applied to the field but I don''t want it to > > > add the field name to the actual error message. > > > > > > For example: > > > > > > errors.add("occurs_on", "The date can''t be today!") unless occurs_on > > > != Date.today > > > > > > I would like the error to read: > > > > > > The date can''t be today! > > > > > > Rather than: > > > > > > Occurs on The date can''t be today! > > > > > > Is there any way to do this? > > > > > > > If you don''t care about the highlighting part, you can use errors.add_to_base. > > Otherwise, you may want to check this out: > > http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors > > _______________________________________________
Thanks Wilson, that works. Dave On 4/23/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:> That''s a Rails ''plugin'', so you need to extract it into the > vendor/plugins/ folder under your Rails project root. > There are some brief instructions at the bottom of the page: > http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors > > On 4/23/06, Dave Verwer <dave@dvhome.co.uk> wrote: > > Thanks Wilson > > > > I do want to keep it specific to the fields so that they highlight, > > the link mentioned in the article you referenced: > > http://wiki.rubyonrails.com/rails/pages/Custom+Error+Message > > > > This seems like about the solution I was looking for, however I am not > > sure how to install it? It comes with an init.rb file and a lib folder > > with one rb file in it. I have put the init.rb in my project root and > > the other file into my lib folder but it doesnt seem to override the > > class. > > > > Anyone any ideas? > > > > > > On 4/22/06, Wilson Bilkovich <wilsonb@gmail.com> wrote: > > > On 4/22/06, Dave Verwer <dave@dvhome.co.uk> wrote: > > > > Hi > > > > > > > > How do I supress the reporting of a field name in the full error > > > > message? I want the error to be associated with the field so that the > > > > .fieldWithErrors class is applied to the field but I don''t want it to > > > > add the field name to the actual error message. > > > > > > > > For example: > > > > > > > > errors.add("occurs_on", "The date can''t be today!") unless occurs_on > > > > != Date.today > > > > > > > > I would like the error to read: > > > > > > > > The date can''t be today! > > > > > > > > Rather than: > > > > > > > > Occurs on The date can''t be today! > > > > > > > > Is there any way to do this? > > > > > > > > > > If you don''t care about the highlighting part, you can use errors.add_to_base. > > > Otherwise, you may want to check this out: > > > http://www.railtie.net/articles/2006/01/26/enhancing_rails_errors > > > _______________________________________________ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >