简体   繁体   English

在Rails 2.x中访问Rails表单错误

[英]Accessing Rails Form Errors in rails 2.x

Is there a way to access form errors in the controller? 有没有办法访问控制器中的表单错误? In the view I can access form errors using 在视图中,我可以使用

from.error_messages

I want to list errors in a flash message before may layout header, how do I go about accessing those errors in the controller so I can assign them to a flash message? 我想在可能出现的布局标题之前在Flash消息中列出错误,如何在控制器中访问这些错误,以便将它们分配给Flash消息?

@model_instance.errors.full_messages.to_sentence

You may find error_messages_for and similar methods to be more convenient way to display errors in another place. 您可能会发现error_messages_for和类似的方法是在其他位置显示错误的更便捷方法。 More details here: 更多细节在这里:
http://guides.rubyonrails.org/activerecord_validations_callbacks.html#displaying-validation-errors-in-the-view http://guides.rubyonrails.org/activerecord_validations_callbacks.html#displaying-validation-errors-in-the-view

What you want well may be already supported, as it's often the case with rails. 您想要的好东西可能已经受到支持,因为滑轨通常就是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM