Rails Devise Invitable gem resend invitation

56 Views Asked by At

I need to resend invitations to users on my app. I know Devise Invitable has a resend_invite method, so calling invite! will resend a new invitation with a new token, but my question is how do I actually code the form?

It would be good to make the form remote: true so I can put it in a few places on the application that it's needed, but how do I code a custom form button or link_to text that I could inject into the code base. Anything that will eventually call User.invite!

Right now, I have this atrocity:

<% resource = access_list.user %>
        <% resource_name = :user %>
        <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
          <%= f.hidden_field :resend_invite, value: true %>
          <%= f.hidden_field :resend_user, value: access_list.user.id %>
          <div class="actions">
            <%= f.submit "resend invite" %>
          </div>
        <% end %>

that touches this:

def update
        if params[:user][:resend_invite] == "true"
            @resend_user = User.find(params[:user][:resend_user])
            @resend_user.invite!
            flash[:alert] = "We've resent an email invitation to #{@resend_user.email}"
        end
            
    super
    
  end

Which works, but is obviously the worst way to do it since it's just piggybacking off the devise controller, not the devise_invitable controller. How do I make it touch the devise_invitable controller?

0

There are 0 best solutions below