I have generated the view with rails generate devise_invitable:views
I have also edited the generated views in users/invitations/new.html.erb to include the fields I want to include first name and last name
<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
<%= render "users/shared/error_messages", resource: resource %>
<% resource.class.invite_key_fields.each do |field| -%>
<div class="field">
<%= f.label field %><br />
<%= f.text_field field %>
</div>
<div class="field">
<%= f.label field %><br />
<%= f.text_field :fist_name %>
</div>
<div class="field">
<%= f.label field %><br />
<%= f.text_field :last_name %>
</div>
<% end -%>
<div class="actions">
<%= f.submit t("devise.invitations.new.submit_button") %>
</div>
<% end %>
I have added this line of code # devise_for :users, controllers: { invitations: 'users/invitations' } to the routes.rb file
I alse created a controller to inherit the Devise controller
class Users::InvitationsController < Devise::InvitationsController
def update
if some_condition
redirect_to root_path
else
super
end
end
def create
end
def new
end
end
yet still, when I go to the new_user_invitation_path to make an invite I get only the email field. please how do I make custom fields?
Assuming you've added the
first_nameandlast_namefields to your user's table.Permitting Custom Fields:
In your
application_controller.rb, permit custom fields when accepting an invitation.This step ensures that the custom fields
:first_nameand:last_nameare permitted when a user accepts an invitation.Invitations Controller:
In your
invitations_controller.rbadd abefore_actionhook to callconfigure_permitted_parameters.In the controller, we are permitting the custom fields
:first_nameand:last_namewhen inviting a user. This ensures that the values entered in the form are accepted when sending an invitation.Invitation Instructions Email Template:
In the
invitation_instructions.html.erbtemplate include the first name and last name of the invited user.--> Skip this if you already have some User Mailer
User Model: Define an
after_createcallback named egsend_admin_mail. This callback method is automatically triggered after a new user is created.Within the send_admin_mail method, after sending you call
UserMailer.welcome_email(self).deliverto send a welcome email to the newly registered user. Here,selfrefers to the instance of the user that triggered theafter_createcallback.By invoking
UserMailer.welcome_email(self), you're passing the user instance to thewelcome_emailmethod in theUserMailerclass, which then uses the user's information to construct and send a personalized welcome email.User Mailer: Assuming you have some Mailer working located in
app/mailers/some_mailer.rbthat defines an email template for sending emails to users. Make sure you are usingApplicationMaileras the base class for your mailer, as shown in this example:--> Skip End
To test sending an invitation to a user, use the invite! class method.
If you have the letter_opener_web gem installed and setup, after sending the email the template will open in your browser interface automatically.
If you run into issues with the above check the Devise Invitable.