Simple_form_for自定义标签

时间:2014-10-09 20:26:55

标签: ruby-on-rails simple-form

<%= f.input :body, 'Send Update:' %>

这会返回Symbol to Integer错误。

我需要标题为“发送更新:”而不是“正文”

的框

2 个答案:

答案 0 :(得分:3)

来自documentation

<%= simple_form_for @user do |f| %>
  <%= f.input :username, label: 'Your username please' %>
  <%= f.input :remember_me, inline_label: 'Yes, remember me' %>
  <%= f.input :email, label_html: { class: 'my_class' } %>
  <%= f.input :password_confirmation, label: false %>

  <%= f.button :submit %>
<% end %>

答案 1 :(得分:2)

也许你正在寻找它的输入之前的标签/文字?您可以在纯文本上编写它,假设您的视图是 html.erb 文件:(使用表格以方便显示)

<table>
 <tr>
  <td>Send Update: </td>
  <td><%= f.input :body %></td>
 </tr>
</table>

或使用f.label

<table>
 <tr>
  <td><%= f.label :body, "Send Update:" %></td>
  <td><%= f.input :body %></td>
 </tr>
</table>   

更新:做一些研究,发现这也可以起作用:

<%= f.input :body, label: "Send Update:" %>