2014-09-02 84 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 %> 
相關問題