I'm sure there are people out there who have done this. I started down it, but I made my app crash a few times, so I figured I'd just ask out there rather than continue driving my webapp in to oblivion. I'm using devise_invitable gem. It sends a link to invited users, they click the link, and they're directed to this view @ app/views/devise/invitation.html.erb:
<h2><%= t 'devise.invitations.edit.header' %></h2>
<%= simple_form_for resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put } do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :invitation_token %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, t("devise.invitations.edit.submit_button") %>
<% end %>
I want to add some fields, for example
<%= f.input :firstname %>
When I do that, though, it does appear in the view, though it's not saving to the User model. So, I figured I needed to modify the controller. That's where I get confused, I think because I'm trying to flop back and forth between the devise and devise_invitable readme's. I'm using devise 3.5.6 and devise_invitable 1.5.5. I tried adding the above input to the form, and changing the applicaiton controller to include
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :firstname
end
but that still doesn't save to my user model. Anyone have any advice?
You are permitting params
that pass on to devise RegistrationsController
create
action. You can see it in definition, below params sanitizer is for :sign_up
devise_parameter_sanitizer.for(:sign_up) << :firstname
In your case it must be :accept_invitation
, Since you are using devise_invitable and form submit url is invitation_path which will submit to Devise::InvitationsController#update
devise_parameter_sanitizer.for(:accept_invitation) do |u|
u.permit(:firstname)
end
More details here