I am trying to create a translatable successful notice. This notice would be called by a successful call of the create and update actions.
This is what I have so far:
#config/locales/en.yml
activerecord:
models:
place: "Place"
successful:
messages:
created: "%{model} was successfully created."
updated: "%{model} was successfully updated."
#app/controllers/places_controller.rb
def create
...
format.html { redirect_to(@place, :notice => "#{t 'activerecord.successful.messages.created'}") }
The problem is that this shows the message: “%{model} was successfully created.”. How do I get it to say: “Place was successfully created.”?
You need to use i18n’s interpolation functions (see http://guides.rubyonrails.org/i18n.html#interpolation) do do something like
where
model_namereturns the name of the class of the created object (see http://api.rubyonrails.org/classes/ActiveModel/Name.html). callinghumanon this object returns the i18n translation of the model name (from the scope activerecord.models.{model_name})