Can anyone help with my problem? When trying to add validation to Model
like “validates_uniqueness_of” and then put <%= error_messages_for
‘article’ %> into view, I get error.
Can someone confirm that this solution works? I have run into this
problem as well and can’t get it to work yet. I use Rails 1.2.3, Ruby
1.8.6. Except for this problem, Gettext works well with rails.
ruby-gettext error_messages_for wasn’t up-to-date with latest rails
changes.
i’ve fixed it in my version, maybe this helps you.
you need to edit gettext’s rails.rb and in module L10n remove
render_error_messages_for and replace the following two functions
(L10n.error_messages_for and ActiveRecordHelper::error_messags_for) by
def error_messages_for(params, klass)
options = params.last.is_a?(Hash) ? params.pop.symbolize_keys
: {}
objects = params.collect {|object_name|
klass.instance_variable_get("@#{object_name}") }.compact
count = objects.inject(0) {|sum, object| sum +
object.errors.count }
unless count.zero?
html = {}
[:id, :class].each do |key|
if options.include?(key)
value = options[key]
html[key] = value unless value.blank?
else
html[key] = 'errorExplanation'
end
end
record =
ActiveRecord::Base.human_attribute_table_name_for_error((options[:object_name]
|| params.first).to_s)
message_title = @error_message_title
message_explanation = @error_message_explanation
header_message = n_(message_title, count) % {:num => count,
:record => record}
error_messages = objects.map {|object|
object.errors.full_messages.map {|msg| klass.content_tag(:li, msg) } }
klass.content_tag(:div,
klass.content_tag(options[:header_tag] || :h2,
header_message) < count}) <<
klass.content_tag(:ul, error_messages),
html
)
end
end
end
def error_messages_for(*params)
L10n.error_messages_for(params, self)
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.