0
votes

I'm using the gem Devise Invitable to send invitations and accept them in my Rails app.

Once the user clicks on the accept invitation link, he is redirected to a page where he can set up his password as expected, however, once I submit the form, it just redirects me back to the same page to set up the password

My form is:

 <%= form_for resource, as: resource_name, url: invitation_path(resource_name),
  html: { method: :put, class: "form-horizontal col-xs-12 col-md-6 col-md-offset-3" } do |f| %>

  <div class="sheet form-sheet">
    <div class="sheet-inner">
      <%= f.hidden_field :invitation_token %>

      <%= f.form_group :password do |f| %>
      <%= f.label :password, class: "form-label" %>
      <%= f.password_field :password, autofocus: true, class: "" %>
      <%= f.error_messages %>
      <% end %>

      <%= f.form_group :password do |f| %>
      <%= f.label :password_confirmation, class: "form-label"  %>
      <%= f.password_field :password_confirmation, class: "" %>
      <%= f.error_messages %>
      <% end %>
    </div>
  </div>

  <div class="form-actions text-right">
    <%= f.submit "Activate Invite", class: 'btn btn-outline-primary' %>
  </div>
  <% end %>

This is the server log when I submit the form:

    Started GET "/users/invitation/accept.14?invitation_token=StRLZtV_B3zEssZ2zKNs" for ::1 at 2016-04-01 23:54:24 +0530
Processing by Devise::InvitationsController#edit as 
  Parameters: {"invitation_token"=>"StRLZtV_B3zEssZ2zKNs"}
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."invitation_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["invitation_token", "dc88f68ca78c337de574137225018e35220d911ca9b1d2a50cf9fe6d103f781d"], ["LIMIT", 1]]
  Rendered devise/invitations/edit.html.erb within layouts/_minimal (2.3ms)
  Rendered layouts/_navbar.html.erb (0.5ms)
Completed 200 OK in 351ms (Views: 347.2ms | ActiveRecord: 0.7ms)

It doesn't seem to be updating the user's password.

I've tried changing the url to user_invitation_path but with no avail.

What am I doing wrong?

1

1 Answers

0
votes

From your logs it is clear that it is not submitting properly for some reason. The form is being submitted with the GET HTTP verb, whereas it must be submitted with a PUT/PATCH HTTP verb for it to call the update action which is where the password will be set.

Please can you check if the invitation_accepted at field was set by any chance? Also can you post the form tag and its contents in plain html by inspecting from the developer tools?

PS: I would ideally add this as a comment however I do not have enough reputation points right now for that.