Rails 3:外部链接上的 before_filter

发布于 2024-12-13 20:10:40 字数 347 浏览 8 评论 0原文

我不知道我的想法是否正确。

在我的 Rails 应用程序中,我使用 Omniauth 进行 facebook 身份验证。

我有 2 个不同的链接“登录”(它们都以 auth/facebook 为目标,并带有回调身份验证/创建)。一个应该重定向到用户个人资料(用户/节目),另一个应该重定向到帖子创建(帖子/新)。

我认为一个好方法是在用户单击“登录”链接之一时存储路径(用户/显示)或(帖子/新),然后在身份验证/创建方法上重定向到此路径。我想到了“auth/facebook”上的 before_filter 。

但 auth/facebook 是 facebook 的外部链接,而不是常规操作。那么我该怎么做呢?

I don't know if I'm thinking the right way or not.

In my rails app, I use facebook authentication with Omniauth.

I have 2 different links "Sign In" (both of them target to auth/facebook with callback authentications/create). One should redirect to the user profile (users/show) and the other one to a post creation (posts/new).

I think a good way to do that is to store the path (users/show) or (posts/new) when the user is clicking on one of the "sign in" links, and then redirect to this path on authentications/create method. I thought about before_filter on "auth/facebook".

But auth/facebook is an external link to facebook and not a regular action. So how can I do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深如许 2024-12-20 20:10:40

我可能会尝试在 auth/facebook 的会话中存储“final_destination”变量。

session[:final_destination] = params[:final_destination]
...
omniauth_does_its_thing
...

您必须将其存储在变量中,因为身份验证/创建可能会使用会话来登录您。

final_destination = session[:final_destination]

在创建的操作结束后:

redirect_to final_destination

redirect_to final_destination_2 if sequels.enjoy?

I might try storing a "final_destination" variable in the session in auth/facebook.

session[:final_destination] = params[:final_destination]
...
omniauth_does_its_thing
...

You would have to store it in a variable because authentications/create is probably going use the session to log you in.

final_destination = session[:final_destination]

After the end of the created action:

redirect_to final_destination

or

redirect_to final_destination_2 if sequels.enjoy?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文