Ask A Question

Notifications

You’re not receiving notifications from this thread.

activeadmin with devise_invitable

Jacob Hedengren asked in Gems / Libraries

Hey everyone,

I know... I'm still using AA... Anyways, I'm looking for a complete guide on being able to invite my non-admin devise users through the admin panel. Strangely I can't find a single, comprehensive enough, resource on this topic. Can't imagine I'm the only one to use devise_invitable with activeadmin. The list of the different errors I encounter trying to implement this is just too long to post. I'm in desperate need of some guidance. Anyone here who can help out? Can't imagine it would be that hard.

Thanks a lot everyone in advance! I appreciate it!

Reply

ChatGPT finally manage to help. For anyone else looking for this functionality;

app/admin/users.rb

ActiveAdmin.register User do
# Permit only necessary parameters for a straightforward invitation
permit_params :email

form do |f|
f.inputs 'Invite user' do
f.input :email
# This setup assumes only the email is necessary for invitations.
# Adjust or add fields as your User model changes.
end
f.actions
end

controller do
def create
user = User.invite!(permitted_params[:user], current_admin_user)

  if user.errors.empty?
    redirect_to admin_users_path, notice: 'User has been successfully invited.'
  else
    # Provides feedback if there are errors with the invitation process
    redirect_to new_admin_user_path, alert: "Error: #{user.errors.full_messages.to_sentence}"
  end
end

end
end

app/models/admin_user.rb

Only add; include DeviseInvitable::Inviter

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.