Reputation: 2101
I have a model called 'dropbox', that extends 'programme'. Programme has the following validation:
validates_presence_of :network_id, :name
and so when you try to create a dropbox, leaving these out, you (unsurprisingly) get the following vaidation message:
* Network can't be blank
* Name can't be blank
Problem is, in the context of 'dropbox', we call 'network' 'category'. How can I change the network can't be blank error message to category can't be blank
---edit---
I've tried:
activerecord:
attributes:
dropbox:
network_id: Category
but this has no affect. However, this works:
activerecord:
attributes:
programme:
network_id: Category
but will change network's name everywhere (where as I just need it to be changed for dropbox). I believe this is because network_id is a property on programme and dropbox just extends this, but there must be a way round!
Upvotes: 0
Views: 360
Reputation: 24803
You could use the locales for that:
activerecord:
attributes:
dropbox:
network: Category
Stick that in config/locales/en.yml to change the displayed names of the attributes. The create some error messages:
errors:
messages:
dropbox:
cant_be_blank: Oops!
Then you add a message option to the model:
validates_presence_of :network_id, :name, :message => I18n.t('activerecord.errors.messages.dropbox.cant_be_blank')
Lots more info can be found here.
Upvotes: 2