Overriding Devise Registration Create Method

Vasseurth picture Vasseurth · Apr 12, 2012 · Viewed 17.3k times · Source

I want to specifically set a field when a user is created. I have

class RegistrationsController < Devise::RegistrationsController
  def create
    super
    @user.tag_list = params[:tags]
  end
end

I have check boxes that pass the tags parameter and I have verified in the server logs that the tags parameter is being passed. However, when I call @user.tag_list in the console I just get a blank response [] .

I feel that the problem lies in my manipulating of the create method of devise. I have not explicitly set @user anywhere but am not sure how to set it using Devise. Does anyone know how to set a specific field when using devise?

Answer

streetlogics picture streetlogics · Oct 27, 2014

For future reference for anyone who finds this while searching for how to override devise methods, most of the Devise methods accept a block, so something like this should work as well:

class RegistrationsController < Devise::RegistrationsController
  def create
    super do
        resource.tag_list = params[:tags]
        resource.save
    end
  end
end