Rails,如何向Devise发布表单? [英] Rails, how to post a form to Devise?

查看:60
本文介绍了Rails,如何向Devise发布表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许我的应用程序上的管理员以任何用户身份登录。我在devise Wiki上找到了以下内容:

I want to allow an admin on my app to sign in as any user. I found the following on the devise wiki:

class AdminController < ApplicationController
  # Sign in as another user if you are an admin
  def become
    return unless current_user.is_an_admin?
    sign_in(:user, User.find(params[:id]))
    redirect_to root_path
  end
end

在视图中,您如何构建一个表格以发布到此?

In the view, how do you build a form to post to this?

谢谢

推荐答案

您甚至不需要构建一个表格中,您只需允许管理员进入以下网址:

You wouldn't even need to build a form, you could simply allow the admin to go to the following url:

example.com/admin/become?id=25

example.com/admin/become?id=25

其中25是您要登录的ID。

where 25 is the id you want to log into as.

因此,使用此方法,您只需创建一个链接即可让管理员单击

So with this method, you would just create a link for an admin to click on.

这篇关于Rails,如何向Devise发布表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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