如何使f.text_field +“<div>有一个错误</div>”工作

时间:2010-08-30 14:06:54

标签: ruby-on-rails

我在applicationhelper中写了一个helper方法,比如这个

str = f.text_field(:username) + "<div class='error'>username is wrong </div>"

然后在我的view.rhtml中显示如下

<input type="text" value="" size="30" name="user[username]" id="user_username">     &lt;div class="errors"&gt;username is wrong&lt;/div&gt;     

有什么帮助吗? THX!

1 个答案:

答案 0 :(得分:2)

str = f.text_field(:username) + "<div class='error'>username is wrong </div>".html_safe