Ruby on Rails Wednesday, October 2, 2013

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)    end  end

routes.rb

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

I followed this 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?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5ba889d8-aba0-46f1-9d90-2fe045826448%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment