0

I need some routes for email confirmation and password reset in Rails for users to click on in emails they receive.

I looked at Railscast #274 - Remember Me & Reset Password and it creates a separate controller for that one Reset action.

Wondering if, because they're both User#email related they might not be better suited as member or collection actions on the User Controller itself?!? Routes like:

/user/reset/:token & /user/confirm/:token or /user/:id/reset/:token & /user/:id/confirm/:token seem plausible but not exactly sure how to create them & what route helper would look like?!?

Or maybe they could both be combined in a single controller? verification/confirm/:token & /verification/reset/:token?

Anyway, just looking for ideas to save me some trial & error. What I don't want is two separate controllers (one for email confirmation and another for password reset).

Meltemi
  • 37,979
  • 50
  • 195
  • 293

1 Answers1

0

This can certainly be done, but it's not RESTful. These resources (confirmations, resets) can be better handled by a dedicated controller with simpler, less-brittle code since it would comply with the REST pattern. Convention over configuration as always... If you find this isn't working for your specific case, by all means do it as you see fit.

PinnyM
  • 35,165
  • 3
  • 73
  • 81
  • could they both be handled in a single RESTful controller? if so, maybe a quick example. thx! – Meltemi Jan 10 '13 at 20:56
  • Not really, they are conceptually separate resources. They can be namespaced though, which is worth considering if you find your controllers are difficult to organize. – PinnyM Jan 10 '13 at 20:56
  • any downside to creating many low-usage and potentially non-usage (in reset's case) controllers in Rails app? – Meltemi Jan 10 '13 at 21:02
  • 1
    Take a look at [Devise's setup for this](https://github.com/plataformatec/devise/tree/master/app/controllers/devise) and you tell me ;) You may be adding a bit of clutter which namespacing can help avoid. Otherwise, I can't think of any downside. – PinnyM Jan 10 '13 at 21:10