2

I'm new to rails, so I'll just explain my situation to you:

I've got a User Model and a UsersController. Users log in with their email address and a password. Special users can invite other users, by typing the email address of the invitee into a form and hitting submit. The invited user then receives a mail containing a link to activate his account, by entering his password for the first time.

Here's the problem:

The "invitation" form is mapped to the create action of my UsersController atm. But what do I map the "activation" form to?

Is it possible for me to define a custom action "activate" or something that can be accessed like /users/3/activate (of course, there should be some authentication token here too...) and would activate the user with id 3?

I've found some stuff on custom actions, but I don't quite get the hang of it yet.

Thx for any help

1 Answer 1

8

You probably have something like this in your routes file. (If not, please post that.)

resources :users 

If you want to add a custom action that acts on a single User, you can add that as a :member like this.

resources :users do
  member do
    get :activate
  end
end

Note that using a get for something that modifies data is a bit wrong, but you're talking about hitting this from a link in an email.

As you play with routes don't forget that rake routes will show you all of the routes that you currently have available to you.

Sign up to request clarification or add additional context in comments.

1 Comment

Hm I just realized that I'll need a GET action for accessing the user activation form from the email link and a POST for actually actually activating the user. thx for the help, I'll give this a try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.