Ruby on Rails 私有链接共享:Google Docs Style [英] Ruby on Rails private link sharing: Google Docs Style

查看:41
本文介绍了Ruby on Rails 私有链接共享:Google Docs Style的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让用户能够共享私人链接的最佳方式是什么,让任何人点击它都可以查看具有隐私限制的特定页面/文档/项目?

What would be the best way to go about giving users the ability to share a private link that enables anyone who clicks it to view a certain page/document/item that have privacy restrictions in place?

就我而言:

用户创建的事件仅限于数据库中的某些关系组(即:朋友、朋友的朋友等)我在事件控制器中有一个 :before_filter 来检查资格当前登录用户的权限,以确保该用户有权查看该事件.如果他们不这样做,他们将被引导到根页面并显示错误消息.

A User creates events which are limited to certain groups of relationships in the database (namely: friends, friends of friends, etc.) I have a :before_filter in the event controller that checks the eligibility of the current logged in user to make sure that that user has permission to see the event. If they don't they get booted to the root page with an error message.

但是,我希望存在一个特殊场景,用户可以使用相同的隐私设置创建事件,此外,还可以通过电子邮件、Facebook 等与他或她的朋友分享特殊链接.那些用户不需要帐户(但需要创建一个帐户才能注册该活动).这很重要,因为 application_controller 中还有一个 :before_filter 可确保用户已登录.

However, I want a special scenario to exist where a user can create an event with those same privacy settings and IN ADDITION, be able to share a special link with his or her friends via e-mail, facebook, etc. Those users do NOT need an account (but will need to make one in order to sign up for the event). This is important because there is also a :before_filter in the application_controller which makes sure a user is logged in.

我想我可以用这里的路由做一些事情...现在我只有简单的/events/72 设置.每个事件是否应该有两个不同的链接:一个普通的链接和一个特殊代码"版本,使它们能够绕过这两个 :before_filter?

I'm thinking there is something I could do with routing here... Right now I just have the simple /events/72 setup. Should each event have two different links: a normal one, and a "special code" version which enables them to bypass those two :before_filter?

人们的想法是什么?

推荐答案

我会有一个单独的控制器,它使用哈希值来引用事件.

I would have a separate controller that uses a hash value to reference the event.

像 created_at + user_id 这样简单的东西经过哈希处理来创建一个唯一的引用.

Something simple like the created_at + user_id hashed to create a unique reference.

您也可以简单地跳过对某个操作的检查,但我更喜欢第一个解决方案.

You could also simply skip the check on a certain action but I would much prefer the first solution .

这篇关于Ruby on Rails 私有链接共享:Google Docs Style的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆