
Interpolation in activerecord.errors.template.header.other & activerecord.errors.template.body not read
Reported by Javix | January 31st, 2011 @ 10:57 AM
I tried to translate the errors message header and body and it
seems that the interpolation didn't work properly.
here is what I did in 'error_messages_helper.rb' file (I use
nifty_generators gem):
[code] module ErrorMessagesHelper
# Render error messages for the given objects. The :message and
:header_message options are allowed. def
error_messages_for(*objects)
options = objects.extract_options!
options[:header_message] ||= t("activerecord.errors.template.header.other")
options[:message] ||= t("activerecord.errors.template.body")
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
unless messages.empty?
content_tag(:div, :class => "error_messages") do
list_items = messages.map { |msg| content_tag(:li, msg) }
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
end
end
end
module FormBuilderAdditions
def error_messages(options = {})
@template.error_messages_for(@object, options)
end
end end
ActionView::Helpers::FormBuilder.send(:include,
ErrorMessagesHelper::FormBuilderAdditions)
[/code] When generating a validation error, I got:
[code] "Impossible d'enregistrer %{model} :
%{count} erreurs" [/code] inteads of the translated model name and
count value.
I also attache the translation 'yml' file.
Comments and changes to this ticket
-
Javix January 31st, 2011 @ 11:01 AM
- no changes were found...
-
Javix March 10th, 2011 @ 05:53 PM
- Tag set to solved
OK, I think that we can close the issue as I found the way to solve the problem.
That's how:- in my view(without using nifty-geberators gem), I had to precise the model to use and count to make them recongnized by interpolation:
<%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= t('errors.template.header', :model=> @user.class.human_name, :count=> @user.errors.count) %></h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %>
The translation file is unchanged as it is on github.
Voilà, hope this helps. -
game online November 30th, 2018 @ 10:38 AM
If you want to play original board game,so friends Mahjong titans is batter choose to play this game,i am very exited play this game,such a good experience http://mahjongfreegames.online/titans so,this is right time to play then create the best new score.
-
Anderfelve1965 February 16th, 2019 @ 02:27 PM
The specialized issues in gadgets are normal and it is difficult for the people to take that gadget to the master in light of the bustling timetable that is the reason to post your inquiry here and find the best solution by bestessays reviews it with the master people.
-
relaxtv March 5th, 2020 @ 10:12 AM
https://www.relaxtv.xyz/showbox-apk/ In this tutorial RelaxTV shares information about CotoMovies APK, here you get installation in Android smartphone, Firestick, Smart TV, PC, etc.
-
peyila March 29th, 2020 @ 09:43 PM
Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates. Traffic Secrets Book
-
peyila March 29th, 2020 @ 09:55 PM
This is very appealing, however , it is very important that will mouse click on the connection: Expert Secrets
-
peyila March 29th, 2020 @ 09:59 PM
Cool you write, the information is very good and interesting, I'll give you a link to my site. DotCom Secrets Review
-
peyila March 29th, 2020 @ 10:05 PM
Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... One Funnel Away Challenge
-
peyila March 29th, 2020 @ 10:10 PM
Listed here you'll learn it is important, them offers the link in an helpful webpage: ClickFunnels
-
peyila April 1st, 2020 @ 03:01 PM
On my website you'll see similar texts, write what you think. 지오바니샴푸
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Repository for collecting Locale data for Ruby on Rails I18n as well as other interesting, Rails related I18n stuff
People watching this ticket
- Nobody is watching this ticket.