You should really be accomplishing this functionality in an after_filter
to your action, rather than in the action itself:
class RegistrationsController < Devise::RegistrationsController
after_filter :create_folder, :only => :create
protected
def create_folder
path = Pathname.new(Rails.root.to_s + '/tmp/') #=> Note 1
directory_name = resource.id.to_s #=> Note 2
Dir.mkdir(path + directory_name) #=> Note 3
end
end
Notes:
- Your syntax for retrieving the project root is incorrect.
:rails_root
can't be interpolated from within single quotes - and it doesn't exist, anyways. TryRails.root.to_s
instead. ":current_user"
is simply a string that will attempt to name the directory:current_user
, which is neither dynamic nor valid. Because your Devise controller has access the the currentresource
(which in this case, represents thecurrent_user
), retrieve theresource.id
and use it instead.- Concatenate the
path
anddirectory_name
together with+
, not,
. There's no need for theunless
conditional, since you're presumably only creating the new folder upon creation of a new user, and each user has a uniqueid
.