提问人:Neon 提问时间:9/14/2022 更新时间:9/14/2022 访问量:85
如何在 rails 中的设计中添加自定义字段 自定义字段是您的姓名和电话号码
How to add custom fields in devise invitables in rails the custom fields is your name and phone number
答:
0赞
mechnicov
9/14/2022
#1
来自自述文件
下面是应用程序控制器可能需要包含的内容的示例,以便将这些参数添加到邀请视图:
class Users::InvitationsController < Devise::InvitationsController
before_action :configure_permitted_parameters
protected
# Permit the new params here.
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:invite, keys: %i[name phone])
end
end
下面是为自定义邀请设置用户名和电话的示例:
<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<% resource.class.invite_key_fields.each do |field| -%>
<div class="field">
<%= f.label field %>
<%= f.text_field field %>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :phone %>
<%= f.text_field :phone %>
</div>
<div class="actions">
<%= f.submit t("devise.invitations.new.submit_button") %>
</div>
<% end %>
评论