I want to send several invitations at one time using the devise-inviteable
gem.
new.html.erb
& lt; H2 & gt; & Lt;% = t "devise.invitations.new.header"%> & Lt; / H2 & gt; & Lt;% = Form_ for the resource, as: = & gt; Source_name ,: url = & gt; Invitation_path (source_name) ,: html = & gt; {: Method = & gt; : Posted} | F | & Gt%; & Lt;% = devise_error_messages! & Gt%; & Lt; Div & gt; & Lt;% resource.class.invite_key_fields.each do | Region | -% & gt; & Lt; P & gt; & Lt;% = f.label field% & gt; & Lt; Br / & gt; & Lt;% = f.email_field field, placeholder: "invitation email"% & gt; & Lt; / P & gt; & Lt;% end -% & gt; & Lt;% = f.collection_select (: role_id, roll.all ,: id ,: role_name, prompts = & gt; true)% & gt; & Lt; / Div & gt; & Lt; P & gt; & Lt;% = f.submit T ("devise.invitations.new.submit_button")%> & Lt; / P & gt; & Lt;% end% & gt;
My Controller: -
Class User :: Invitation Controller & lt; Quit the Devise :: InvitationsController def if the query [: user] [: email] == "" || Params [: user] [: role_id] == "" Flash [: warning] = "Please enter the email first and choose a role for the invite" redirect_to new_user_invitation_path and others if User.invite! (: Email = & gt; params [: user] [: Email] ,: current_user.id ,: type = & gt; employee ',: role_id = & gt; para [[user] [: role_id ]) Flash [: notice] = "Invitation successfully sends" Redirect_to new_user_invitation_path else flash [: warning] = "Invitation has not been sent." Redirect_to new_user_invitation_path End and end and piece
I think the solution is to send a separate email with a comma in the invite but how can I pass it? I do not really know how to
If you have any other solutions please let me know.
Thank you.
I have trouble with this problem but in the end I have got the solution to send multiple invitation emails .
Below I interpret my code as to how I can do this.
This is my html view.
new.html.erb
& lt; H2 & gt; & Lt;% = t "devise.invitations.new.header"%> & Lt; / H2 & gt; & Lt;% = Form_ for the resource, as: = & gt; Source_name ,: url = & gt; Invitation_path (source_name) ,: html = & gt; {: Method = & gt; : Posted} | F | & Gt%; & Lt;% = devise_error_messages! & Gt%; & Lt; Div & gt; & Lt;% resource.class.invite_key_fields.each do | Region | -% & gt; & Lt;% = f.label field% & gt; & Lt; Br / & gt; & Lt;% = f.email_field Field, Name: "User [Email] []", Placeholder: "Invitation Email", Required: True% & gt; & Lt; / P & gt; & Lt; Div id = "createNewTextbox" & gt; & Lt; / Div & gt; & Lt; An id = "btnLinkCreate" href = "#" onClick = "create_new ();" & Gt; + INVITE more & lt; / A & gt; & Lt;% end -% & gt; & Lt; / Div & gt; & Lt; P & gt; & Lt;% = f.submit T ("devise.invitations.new.submit_button")%> & Lt; / P & gt; & Lt;% end% & gt;
In this I take the default with a text-box name: "User [email] []" (This is important because the use of this rail automatically creates an email array And sends the form you submit the form)
I also generate a dynamic text box using Javascript and clicking on more links button will give it below.
& lt; Div id = "create new text box" & gt; & Lt; / Div & gt; & Lt; An id = "btnLinkCreate" href = "#" onClick = "create_new ();" & Gt; + INVITE more & lt; / A & gt;
Here's my dynamic text box code javascript.
$ ('# createNewTextbox') .andand ('' ;);
Now you can see that I give the same name as the dynamic text box (name = "user [email] []"), so the train automatically hash array like this Make:
"Users" => {"Email" = & gt; {"Email-1", "email-2", "email-3" ...}}
It is now close to creating a hash array method in which we receive each email
My Controller: -
Class User: InvitationsController & lt; Devise :: InvitationsController def params [: Users] [: Email] .each do | Email |
If you still have any questions, please tell me the comment I
No comments:
Post a Comment