Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RoR:Desive控制器是自动生成的还是我们应该自己编写?_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails RoR:Desive控制器是自动生成的还是我们应该自己编写?

Ruby on rails RoR:Desive控制器是自动生成的还是我们应该自己编写?,ruby-on-rails,devise,Ruby On Rails,Devise,我是RubyonRails新手。我正在尝试使用Desive gem进行身份验证。我正在学习github中的教程。我已经使用rails生成designe:views创建了designe视图。但是我找不到任何控制器。我是否需要自己创建,或者是否有任何命令为其生成控制器? Plz helpDesive已经在幕后为您创建了所需的控制器。这些控制器中很少有:RegistrationController,SessionController 要自定义或覆盖任何控制器,请说RegistrationControl

我是RubyonRails新手。我正在尝试使用Desive gem进行身份验证。我正在学习github中的教程。我已经使用rails生成designe:views创建了designe视图。但是我找不到任何控制器。我是否需要自己创建,或者是否有任何命令为其生成控制器?
Plz help

Desive已经在幕后为您创建了所需的控制器。这些控制器中很少有:
RegistrationController
SessionController

要自定义或覆盖任何控制器,请说
RegistrationController
;您可以执行以下操作(my one应用程序中的代码片段):

类注册控制器[:destroy]
def新
超级的
结束
def创建
如果简单验证码有效#通过验证码验证用户注册
超级的
其他的
建设资源
清除密码(资源)
flash.now[:alert]=“下面的验证码有错误。请重新输入代码。”
渲染:新
结束
结束
def更新
#密码为空时提交设置表单所需
如果参数[:用户][:密码]。为空?
参数[:用户]。删除(“密码”)
参数[:用户]。删除(“密码确认”)
结束
@user=user.find(当前用户id)
如果@user.update_属性(参数[:user])
设置闪光信息:通知:更新
#如果用户的密码发生更改,请绕过验证登录该用户
在@user中签名:旁路=>true
重定向到(@user)的更新后路径
其他的
渲染“编辑”
结束
结束
def销毁
@user=user.find(参数[:id])
@用户破坏
将_重定向到rooth_路径
结束
结束

有关更多信息,请参见:

我在这里找不到任何控制器。这些控制器是何时生成的?它使用存在于gem配置中(并安装在应用程序中)的Desive gem控制器。您不会直接在应用程序的
应用程序/控制器/
中看到它们。
class RegistrationsController < Devise::RegistrationsController
  before_filter :admin_user, :only => [:destroy]

  def new
    super
  end

  def create
    if simple_captcha_valid? #verifying user registration by captcha
      super
    else
      build_resource
      clean_up_passwords(resource)
      flash.now[:alert] = "There was an error with the captcha code below. Please re-enter the code."      
      render :new
    end
  end

  def update
    # required for settings form to submit when password is left blank
    if params[:user][:password].blank?
      params[:user].delete("password")
      params[:user].delete("password_confirmation")
    end

    @user = User.find(current_user.id)
    if @user.update_attributes(params[:user])
      set_flash_message :notice, :updated
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy
    redirect_to rooth_path
  end
end