2012-08-08 69 views
22

我想使用簡單形式將默認值添加到文本輸入字段。 隨着:placeholder它不作爲默認....將簡單形式的默認值添加到文本輸入

<%= f.input :user, :placeholder => '[email protected]' %> 
+0

要有默認值,並在字段中保留實際值(例如用戶的電子郵件),請嘗試像這樣--- f.input:user,input_html:{value:@ user.email.present? ? @ user.email:'[email protected]'}。也可以在RoR – 2016-06-09 18:02:05

回答

50
<%= f.input :user, :input_html => { :value => '[email protected]' } %> 
+3

中使用新的更具可讀性的語法也許,':input_html => {:value =>'[email protected]'}' – 2012-08-08 19:37:39

+0

是的,也意識到了這一點。修復。 – pgrosslicht 2012-08-08 19:38:49

+0

@kishie謝謝。它確實有用! – Mark 2012-08-08 19:39:33

5

你可以簡單地做:

<% f.text_field, value: '[email protected]' %> 

text_field是好的,如果你是喜歡洗劫形式的搜索寶石工作。

+3

我認爲如果您不使用:input_html選項並且只使用:value或value:那麼每次您返回到編輯頁面時,該值將被重置爲默認值。 – 2014-01-14 17:21:16

相關問題