(少なくとも私にとって) 問題は、検証が実際にオンになったときのキーをオブジェクトでf.select :whatever_id
探していたことでした。object.errors
:whatever_id
:whatever
:whatever_id
変更することで、この厄介な問題を回避しました
object.errors.on(@method_name)
に
object.errors.on(@method_name) || object.errors.on(@method_name.gsub(/_id$/, ''))
これが差分です(Rails 2.3.4に対する):
diff --git a/vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb b/vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb
index 541899e..5d5b27e 100644
--- a/vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -247,7 +247,7 @@ module ActionView
alias_method :tag_without_error_wrapping, :tag
def tag(name, options)
if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(tag_without_error_wrapping(name, options), object.errors.on(@method_name))
+ error_wrapping(tag_without_error_wrapping(name, options), object.errors.on(@method_name) || object.errors.on(@method_name.gsub(/_id$/, '')))
else
tag_without_error_wrapping(name, options)
end
@@ -256,7 +256,7 @@ module ActionView
alias_method :content_tag_without_error_wrapping, :content_tag
def content_tag(name, value, options)
if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(content_tag_without_error_wrapping(name, value, options), object.errors.on(@method_name))
+ error_wrapping(content_tag_without_error_wrapping(name, value, options), object.errors.on(@method_name) || object.errors.on(@method_name.gsub(/_id$/, '')))
else
content_tag_without_error_wrapping(name, value, options)
end