Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Change Error Message

I have an error message that appears when my the field for the database :b_name is empty. However, b_name stands for Business Name and I have made the label say that. However, when I get the error message, it says B name cant be blank. Is there any way I can change it so when I get the error it says Business Name can't be blank instead of b_name cant be blank?

like image 494
Jake Avatar asked Jun 24 '11 21:06

Jake


1 Answers

Yes it is actually really simple.

You should have a file named config/locales/en.yml, if not simply create one. There you can add your own custom names.

en:
  activerecord:
    models:
      order:            "Order"
    attributes:
      order:
        b_name:         "Business Name"

That will replace your b_name for "Business Name"

Your Order model in app/models/order.rb should look like:

class Order < ActiveRecord::Base
  validates :b_name, :presence => true
  .
  . 
  .

Please let me know if it worked :)

Here is an screenshot of my app working fine. Here is an screenshot of my app working

like image 99
rogeliog Avatar answered Sep 22 '22 13:09

rogeliog