Guest User

Untitled

a guest
Nov 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. class Users::InvitationsController < Devise::InvitationsController
  2. private
  3. def resource_params
  4. params.permit(user: [:email, :invitation_token, :role, :company_id])[:user]
  5. end
  6. end
  7.  
  8. class InvitationsController < Devise::InvitationsController
  9. before_action :update_sanitized_params, only: :update
  10.  
  11. # PUT /resource/invitation
  12. def update
  13. respond_to do |format|
  14. format.js do
  15. invitation_token = Devise.token_generator.digest(resource_class, :invitation_token, update_resource_params[:invitation_token])
  16. self.resource = resource_class.where(invitation_token: invitation_token).first
  17. resource.skip_password = true
  18. resource.update_attributes update_resource_params.except(:invitation_token)
  19. end
  20. format.html do
  21. super
  22. end
  23. end
  24. end
  25.  
  26.  
  27. protected
  28.  
  29. def update_sanitized_params
  30. devise_parameter_sanitizer.permit(:accept_invitation, keys: [:password, :password_confirmation, :invitation_token, profile_attributes: [:first_name, :last_name]])
  31. end
  32. end
  33.  
  34. <%= f.fields_for :profile do |p| %>
  35. <div class="form-group">
  36. <%= p.label :first_name, class: 'sr-only' %>
  37. <%= p.text_field :first_name, autofocus: true, class: 'form-control', placeholder: 'First name' %>
  38. </div>
  39.  
  40. <div class="form-group">
  41. <%= p.label :last_name, class: 'sr-only' %>
  42. <%= p.text_field :last_name, class: 'form-control', placeholder: 'Last name' %>
  43. </div>
  44. <% end %>
  45.  
  46. ...
  47. accepts_nested_attributes_for :profile, reject_if: proc { |attributes| attributes[:first_name].blank? }
Add Comment
Please, Sign In to add comment