How to override devise registrations controller

让人想犯罪 __ 提交于 2019-12-14 03:59:59

问题


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?


回答1:


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

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

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


来源:https://stackoverflow.com/questions/10304455/how-to-override-devise-registrations-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!