Rails 3 - DevID重定向到sign_in后形成 [英] Rails 3 - Devise redirects to form after sign_in

查看:118
本文介绍了Rails 3 - DevID重定向到sign_in后形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在博客应用程序中,我希望每个用户访问表单以发表评论。

In a blog app I want every user to access a form to post a comment.

当用户提交评论表单时,他被重定向到Devise sign_in表单如果未登录。

When the user submit the comment form he is redirected to the Devise sign_in form if is not logged in.

before_filter :authenticate_user!, :except => [:index, :show, :new]

我怎么能一旦用户sign_in,将他重定向评论表单填写所有字段?

How could I once the user sign_in, redirect him to the comment form and fill all fields ?

提前感谢

推荐答案

如果您希望在每次登录后将用户注解为表单,请添加ApplicationController:

If you want to take the user to comment form after every sign in, add in ApplicationController:

#after_sign_in_path_for is called by devise
def after_sign_in_path_for(resource_or_scope)
  comment_path...
end

如果您想将用户重新登录到登录前的页面,您可以将会话中的当前控制器+操作保存回来并重定向到:

If you want to take user back to the page they were at before sign in, you could save the current controller+action in session and redirect back:

session[:pre_login_controller] = params[:controller]
session[:pre_login_action] = params[:action]

然后:

def after_sign_in_path_for(resource_or_scope)
  if session[:pre_login_controller] && session[:pre_login_action]
    "#{session[:pre_login_controller]}/#{session[:pre_login_action]}"
  else
     some default path -- root url or comment path etc
  end
end

这篇关于Rails 3 - DevID重定向到sign_in后形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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