Search code examples
ruby-on-rails-3devisecontrollerrubygems

Edit Devise Controller - Add Object


I want to add an object (@attachment) to the new and edit actions in the controller for devise. Unfortunately I don't know how and where to do this. :|


Solution

  • You can customize the registrations controller with the same approach shown in the docs: https://github.com/plataformatec/devise#configuring-controllers

    And you could instantiate the object using a private method and before_filter, like so:

    #in controllers/registrations_controller.rb
    class RegistrationsController < Devise::RegistrationsController
      before_filter :init_attachment, only: [:new, :edit]
    
      private
      def init_attachment
        @attachment #= ...
      end
    end
    

    Hope it helps!