2014-09-02 76 views
0

我正在使用simple_form_for生成表单。Rails - 如何在simple_form_for表单中添加自己的标签?

这是一种标准的方式如何呈现输入:

<%= f.input :password, input_html: { class: 'textinput' }, :required => true, :autofocus => true, :placeholder => 'this is heavy' %> 

simple_form官方Github的页面显示这种方式来做到这一点:

<%= f.input :password, label: 'Password (at least 8 characters)', input_html: { class: 'textinput' }, :required => true, :autofocus => true, :placeholder => 'this is heavy' %> 

但是,当我将它设置这样,标签仍然说密码,而不是密码(至少8个字符)

我在做什么错?

回答

0

尝试在标签中使用双引号而不是单引号。

<%= f.input :password, label: "Password (at least 8 characters)", input_html: { class: 'textinput' }, required: true, autofocus: true, placeholder: "this is heavy" %> 
0

您的标签应与您的输入分开。

<%= f.label :password, "Password (at least 8 characters)" %> 
    <%= f.input :password, input_html: { class: 'textinput' }, :required => true, :autofocus => true, :placeholder => 'this is heavy' %> 

这也显示在Simple Form Git Repo

简单的表单,您还可以使用标签,提示,input_field,错误和full_error佣工(请大家看看rdocs每种方法的详细信息):

<%= simple_form_for @user do |f| %> 
    <%= f.label :username %> 
    <%= f.input_field :username %> 
    <%= f.hint 'No special characters, please!' %> 
    <%= f.error :username, id: 'user_name_error' %> 
    <%= f.full_error :token %> 
    <%= f.submit 'Save' %> 
<% end %> 
相关问题