Forum: Ruby on Rails When overriding the registration controller from devise, is it possible to access the newly created

5a41028798f4e263c2d0692f5b1847ec?d=identicon&s=25 Monserrat Foster (Guest)
on 2013-10-02 17:43
(Received via mailing list)
I'm trying to create a folder right after a user registers, so I
override
the create action on the registration controller (devise) but I don't
know
how to access the newly created user in order to create the folder with
it's name to upload files later.

So far I've got this:

class RegistrationsController < Devise::RegistrationsController

  def new
    super
  end

  def create
    super
    create_folder
  end

  def update
    super
  end

  def create_folder
    path =  Pathname.new(':rails_root/tmp/')
    directory_name = ":current_user"
    Dir.mkdir(path, directory_name) unless File.exists?(directory_name)
  endend

routes.rb

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

I followed
this<http://stackoverflow.com/questions/3546289/overrid...
to
override the registration controller.

   1. Should I leave it there or move it to the create action? Instead
of
   using a method
   2. is that the right way to access the current user?
   3. Maybe instead of registration it's better to do it on sign in?
52f3528c40e9cf28ad0900886eecb128?d=identicon&s=25 Jordon Bedwell (Guest)
on 2013-10-02 17:51
(Received via mailing list)
On Wed, Oct 2, 2013 at 10:41 AM, Monserrat Foster
<monsefoster@gmail.com> wrote:
> is that the right way to access the current user?
> Maybe instead of registration it's better to do it on sign in?

I don't know how you have your application encapsulated or even what
you consider behavior but if it were me I would skip trying to be
clever and skip trying to override methods I have no business being in
and simply hook into creation on the model:
http://api.rubyonrails.org/classes/ActiveRecord/Ca... --
http://api.rubyonrails.org/classes/ActiveModel/Cal... just
because it's tied to the database does not mean it's strictly an
interface between your app and the database ;).
72d362060aed96f3de7e1d4ca54f3dcc?d=identicon&s=25 Scott Eisenberg (Guest)
on 2013-10-02 20:47
(Received via mailing list)
There is a resource object about that should have the newly created
user.

Check out:

http://stackoverflow.com/questions/4702806/how-to-...

This methodology worked well for me.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.