error_messages_for

本文解答了一个关于Ruby on Rails应用中如何正确使用error_messages_for显示表单验证错误的问题。作者解释了error_messages_for的工作原理,并给出了实例说明如何针对不同变量名的对象正确调用此方法。
 在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'...
(venv) gapinyc@DESKTOP-9QS7RL5:~/superset/venv/lib/python3.10/site-packages/superset/translations$ pybabel compile -d . -l zh error: ./zh/LC_MESSAGES/messages.po:154: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:158: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:162: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:281: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:1177: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:1626: incompatible format for placeholder 1: 's' and 'd' are not compatible error: ./zh/LC_MESSAGES/messages.po:3614: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:3728: unknown named placeholder 'name' error: ./zh/LC_MESSAGES/messages.po:4468: unknown named placeholder 'columns' error: ./zh/LC_MESSAGES/messages.po:5945: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:9381: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:9901: placeholders are incompatible error: ./zh/LC_MESSAGES/messages.po:10645: unknown named placeholder 'table_name' error: ./zh/LC_MESSAGES/messages.po:12956: positional format placeholders are unbalanced error: ./zh/LC_MESSAGES/messages.po:14236: positional format placeholders are unbalanced error: ./zh/LC_MESSAGES/messages.po:14245: positional format placeholders are unbalanced compiling catalog ./zh/LC_MESSAGES/messages.po to ./zh/LC_MESSAGES/messages.mo 16 errors encountered. (venv) gapinyc@DESKTOP-9QS7RL5:~/superset/venv/lib/python3.10/site-packages/superset/translations$ file zh/LC_MESSAGES/messages.mo zh/LC_MESSAGES/messages.mo: GNU message catalog (little endian), revision 0.0, 2474 messages, Project-Id-Version: Apache Superset 0.22.1 '\346\255\244\350\277\207\346\273\244\346\235\241\344\273\266\346\230\257\344\273\216\347\234\213\346\235\277\344\270\212\344\270\213\346\226\207\347\273\247\346\211\277\347\232\204\343\200\202\344\277\235\345\255\230\345\233\276\350\241\250\346\227\266\344\270\215\344\274\232\344\277\235\345\255\230\343\200\202' (venv) gapinyc@DESKTOP-9QS7RL5:~/superset/venv/lib/python3.10/site-packages/superset/translations$
10-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值