设计邀请批量邀请 - Ruby on Rails
我正在尝试使用 Devise invitable 来一次添加多个用户。基本上,当有人创建帐户时,他们要做的第一件事就是使用可邀请表单添加一堆用户......
只是不确定如何复制表单中的字段并让他们为每个条目发送创建请求。
提前致谢!
I'm trying to user Devise invitable to add multiple users at once. Basically when someone creates an account, the first thing they'll want to do is add a bunch of users using the invitable form...
just not sure how to duplicate fields in the form and have them send a create request for each entry.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我就是这样做的。
对于此示例,我们假设有一个用户模型和一个用户控制器。
定义batch_invite操作的路由。
在users_controller中定义batch_invite操作
在文本区域中接受以逗号分隔的电子邮件列表的表单。 >
一些注意事项:
如果您喜欢精简控制器,您可以将逻辑移至模型,例如,通过在用户模型中创建 send_batch_invitations 方法并传递params[:user_emails] 作为来自 users 控制器的该方法的参数。
由于发送邀请的方法可能需要足够的时间才能完成,我建议您将此任务分配给后台作业处理器,例如 delayed_job 或 resque。
有 railscasts 演示了这两个后台作业处理器的用法。
This is how I would do it.
Lets assume a User model and a users controller for this example.
Define a route for the batch_invite action.
Define the batch_invite action in the users_controller
A form that accepts a comma-separated list of emails in a textarea.
A couple of notes :
If you like your controller skinny, you could move the logic to the model, for instance, by creating a send_batch_invitations method in your User model and pass the params[:user_emails] as an argument to that method from the users controller.
Since the method that sends the invitations could take sufficient time to complete, I would suggest you assign this task to a background job processor, such as delayed_job or resque.
There are railscasts that demonstrate the usage of these two background job processors.