Monserrat Foster
2013-Oct-02 15:41 UTC
When overriding the registration controller from devise, is it possible to access the newly created
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/override-devise-registrations-controller>
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.
Jordon Bedwell
2013-Oct-02 15:49 UTC
Re: When overriding the registration controller from devise, is it possible to access the newly created
On Wed, Oct 2, 2013 at 10:41 AM, Monserrat Foster <monsefoster-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > > > Should I leave it there or move it to the create action? Instead of using a > method > 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/Callbacks.html -- http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html just because it''s tied to the database does not mean it''s strictly an interface between your app and the database ;). -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnzKCNaHdBEn9CEORkGkkpjbYQm9rM%2BZWzg79py_b8J%3DzA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Scott Eisenberg
2013-Oct-02 18:45 UTC
Re: When overriding the registration controller from devise, is it possible to access the newly created
There is a resource object about that should have the newly created user. Check out: http://stackoverflow.com/questions/4702806/how-to-add-callback-after-registration-with-rails3-and-devise This methodology worked well for me. On Oct 2, 2013, at 11:49 AM, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Oct 2, 2013 at 10:41 AM, Monserrat Foster <monsefoster-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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: >> >> >> Should I leave it there or move it to the create action? Instead of using a >> method >> 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/Callbacks.html -- > http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html just > because it''s tied to the database does not mean it''s strictly an > interface between your app and the database ;). > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnzKCNaHdBEn9CEORkGkkpjbYQm9rM%2BZWzg79py_b8J%3DzA%40mail.gmail.com. > For more options, visit https://groups.google.com/groups/opt_out.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5AEE5091-E243-4298-8C9A-B9FD13E91EB5%40btrtrucks.com. For more options, visit https://groups.google.com/groups/opt_out.