-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize Invite Forms #770
Comments
You can generate scoped views for each model: |
Thanks. So I have one single Devise user model but there is a type attribute that categorizes each user. Depending on this type, I want to create different invite forms. |
So I created another Devise model and now I have the following structure - - Staff Model (Devise) - Users model (Devise) However, my admin is a part of the Users model and is only able to invite Users and not able to invite Staff. How to let the admin invite both ? |
With one model you should use one view, and you can render a different partial depending on type in that view. You don't need to create a different devise model if you don't want to, I thought you had 2 models. If you want to use different models, but invite them from one model, you have to change authenticate_inviter!, explained in README |
Thanks, that really helps. Also, if my devise model has_many roles and if the admin wants to assign the roles while creating the invitation, I am guessing the def create method in invitations controller would need to be tweaked along with wihitelisting the roles attributes? I tried this but not able to succeed - def create
params[:staff][:approle_ids].each do |role|
if !role.empty?
resource.approles.build(:usertype_id => role)
end
end
super
end` |
invite_params will be assigned to resource, so you shouldn't need to tweak create method, as you can see in lines: resource is assigned with result of calling invite! with invite_params However your approle_ids looks like role_ids, so you can't assign them directly to approle_ids. Perhaps, you may use different name, like role_ids, and add role_ids= method to your model. I think you are trying to build approles in resource before calling super, so self.resource is not assigned yet, not sure what default value is returning devise for resource, but calling super will override it, so your approles are lost. You may try overriding invite_resource with block, so block is passed to invite!: def invite_resource(&block)
super do |resource|
params[:staff][:approle_ids].each do |role|
resource.approles.build(:usertype_id => role) unless role.empty?
end
end
end |
Ok great thanks, this works. I have another question - Admin (User model with Admin role assigned) is responsible for sending the invites to new users but the invite must be approved by the Director (User model with Director role assigned) first and only then the invitation should be sent via email. Also, there are additional fields such as Name, address etc. when the admin sends the invite. Is there an inbuilt devise-invitable feature? If not, is the following the correct way to tackle this ? Admin fills a simple form with all staff details and sends to Director for approval. |
You can create another model, it would work but probably not needed. Also, you can send skip_invitation in admin form (add it to invite_params), or override some controller method to set skip_invitation to true as explained in README (set in invite_resource for example). Then director may review invitations which are not sent and approve them which would call user.deliver_invitation to send email. |
Hi, I have two different types of user groups for my app. 'Customer' and 'Staff'. When the admin is sending an invite, I am trying to create different forms for both groups to ensure appropriate inputs for each are filled up.
Please let me know how to go about doing this?
The text was updated successfully, but these errors were encountered: