Matt Elhotiby
Matt Elhotiby

Reputation: 44066

How do i skip activation in rails?

I am using the restful authentication plugin in rails and i need to skip the authorization and log the user in immediately...How can this be done

Any ideas would be highly appreciated

Upvotes: 0

Views: 125

Answers (2)

Jagira
Jagira

Reputation: 1368

Write an activation method in after_create callback. The code depends on you gem/plugin. In most of the gems it will be like user.activate . Or build your custom method, nullify the activation code, update the activated_at at time and call this method in after_create callback.

Upvotes: 0

Steve Ross
Steve Ross

Reputation: 4144

If I recall correctly, you can install Restful Authentication without an activation requirement. To do this, just do:

script/generate authenticated user sessions

If, however, you need activation, then you do:

script/generate authenticated user sessions --include-activation

and the ActionMailer code is created.

So the first direction you can go is simply not ask for any activation mechanism in the first place. If you do need activation, but only want to avoid it in certain circumstances, you need to understand how activation works. I really recommend reading the code here, but it's pretty basic. There is a column called activated and if it's true, then the user is activated. In theory, you can simply set it to true and march onward.

Logging the user in is also something you can look up in the code. The easiest way to do it is set session[:current_user] to the id of the user you just created.

And... write tests first. When the tests pass, then you know you have the right solution :)

Upvotes: 1

Related Questions