在http://www.ruby-forum.com/topic/114652#new论坛中看到如下问题:
I have a database table called "hvd_codes", the model is called HvdCode.
In my form partial, what should I enter as a parameter to
error_messages_for? I've tried <%= error_messages_for 'hvd_codes' %> but nothing is
displayed.
IRC error_messages_for simply looks for a global variable named after
its parameter and parse the result 'errors' called on it.
So if you have a @hvdcode which is a HvdCode instance, just use
'hvdcode'. If you had a @foo instance of HvdCode, you'd use 'foo'...
本文解答了一个关于Ruby on Rails应用中如何正确使用error_messages_for显示表单验证错误的问题。作者解释了error_messages_for的工作原理,并给出了实例说明如何针对不同变量名的对象正确调用此方法。
336

被折叠的 条评论
为什么被折叠?



