How to add custom fields in devise invitables in rails the custom fields is your name and phone number

99 Views Asked by At

Actually Ineed the exact code for this problem, I am working on it but face errors on it

1

There are 1 best solutions below

0
mechnicov On

From README

Here is an example of what your application controller might need to include in order to add these parameters to the invitation view:

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

Here is an example setting a User's name and phone for a custom invitation:

<%= 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 %>