如何覆盖设计注册控制器 [英] How to override devise registrations controller

查看:110
本文介绍了如何覆盖设计注册控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据此 railscast 发送邀请,我正在使用devise进行身份验证我的应用程序。我想要实现这一点代码:

I am working on invitations per this railscast and I am using devise for authentication in my app. I would like to get this bit of code implemented:

def new
  @user = User.new(:invitation_token => params[:invitation_token])
  @user.email = @user.invitation.recipient_email if @user.invitation
end

。这涉及覆盖注册控制器。这是注册控制器中的新操作:

inside of devise. This involves overriding the registrations controller. Here is the new action that is in the registrations controller:

  def new
    resource = build_resource({})
    respond_with resource
  end

我是编码的新手,筛选设计代码并找出发生了什么,但似乎令人望而生畏。有什么简单的东西吗?如何通过覆盖设计注册控制器来实现代码?

I am relatively new to coding and made an attempt to sift through the devise code and figure out what's going on, but seems daunting. Is there something simple to this? How can I get that code implemented by overriding the devise registrations controller?

推荐答案

他甚至给了错误?另一件事,你改变了routes.rb?示例:

He even gave an error? Another thing, you changed your routes.rb? example:

devise_for :users, :controllers => { :registrations => "registrations" }

在他的方法new中,添加super

In his method "new", add the super

def new
  @user = User.new(:invitation_token => params[:invitation_token])
  @user.email = @user.invitation.recipient_email if @user.invitation
  super
end

这篇关于如何覆盖设计注册控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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