rails gem Devise Invitable accept view issue

1.4k views Asked by At

I would like to have access to the user information in the invitation/accept route. When I go to the form and use

<%= resource.name %>

it won't display the User. It also appears that it isn't loading the user during the accept. Is there an easy way to show the user some information about the invite?

1

There are 1 answers

0
Stefan Pettersson On BEST ANSWER

I can think of two options:

  1. You could override the devise invitable controller, see: Anyone have experience with devise_invitable?

  2. In my case, I wanted to pass the name of the invitor.

    • I add an integer attribute 'invitor' to the User class. This is the id of the invitor Person. Don't forget to add 'invitor' as attr_accessible in the model.
    • I already had a 'name' string attribute in the User class.
    • In the app/views/{users|devise}/invitations/new.html.erb (path may vary depending on how you generated the views) add a hidden form field with the logged in user (invitor):

    ... <%= f.text_field :invitor, :value => current_user.id, :hidden => true %> ...

    • In the email text app/views/{users|devise}/mailer/invitation.html.erb I can refer to the invitor:

    ... <%= (User.find @resource.invitor).name %> has invited you to <%= root_url %>, you can accept it through the link below....

Not that elegant, but it works. Improvements that survive updates of the devise_invitable gem are welcome.