我有一个名为discount_info的属性。我想在设计编辑表单中创建另一个字段,以便用户可以编辑此信息。我想将该字段设为text_area。我不知道如何在rails中做到这一点。
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :address %><br />
<%= f.email_field :address, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
答案 0 :(得分:1)
<%= f.text_area :discount_info, :class => "", :placeholder => "if you want a placeholder" %>
答案 1 :(得分:0)
只需在form
方法中添加configure_permitted_parameters
及 许可 中的属性。
<div class="field">
<%= f.label :discount_info %><br />
<%= f.text_area :discount_info %>
</div>
在控制器中
def configure_permitted_parameters
#other code
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:other_attributes, :discount_info) }
end