Forum: Ruby on Rails restful_autentication activation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John B. (Guest)
on 2007-02-22 11:46
Hi,

I am using the restfull authentication plugin for my website.  I am
getting to grips with the rest routes but when a user wnats to activate
their account i am not too sure how to set this up.

In the controller:

users_controller.rb
def activate
    self.current_user =
User.find_by_activation_code(params[:activation_code])
    if logged_in? && !current_user.activated?
      current_user.activate
      flash[:notice] = "Signup complete!"
    end
    redirect_back_or_default('/')
end

routes.rb
map.resources :users, :member => { :activate => :get }

Now what this will give me is the following url: /users/:id;activate/ so
if i had  the id of the user this would work /users/1;activate/ but i
dont i have the activation code so something like
/users/1f724a1fe4d5152f3138c;activate/

How can i set this up so in the url i can take the activation code, find
out which user it is and activate them using rest.  Is it soemthing to
do with the :format .

Any advice appreciated.

JB
John B. (Guest)
on 2007-02-22 19:54
John B. wrote:
> Hi,
>
> I am using the restfull authentication plugin for my website.  I am
> getting to grips with the rest routes but when a user wnats to activate
> their account i am not too sure how to set this up.
>
> In the controller:
>
> users_controller.rb
> def activate
>     self.current_user =
> User.find_by_activation_code(params[:activation_code])
>     if logged_in? && !current_user.activated?
>       current_user.activate
>       flash[:notice] = "Signup complete!"
>     end
>     redirect_back_or_default('/')
> end
>
> routes.rb
> map.resources :users, :member => { :activate => :get }
>
> Now what this will give me is the following url: /users/:id;activate/ so
> if i had  the id of the user this would work /users/1;activate/ but i
> dont i have the activation code so something like
> /users/1f724a1fe4d5152f3138c;activate/
>
> How can i set this up so in the url i can take the activation code, find
> out which user it is and activate them using rest.  Is it soemthing to
> do with the :format .
>
> Any advice appreciated.
>
> JB

I know how to do it using named routes, something like the below, i was
wondering if there was a more restfull way of doing this as all i have
is the activation code.

map.activate 'activate/:activation_code', :controller => 'users',
:action => 'activate'
This topic is locked and can not be replied to.