Re: can all methods be made to fit REST?

Jon Garvin
2007-10-18T18:20:39Z

Ant wrote:
> I know that if you listen to DHH and similar REST evangelists that
> they would have you believe that all methods can be reduced to the
> seven that fit the REST conventions (create, show, update, destroy,
> index, new, and edit). I am not yet convinced.
>
> For example can anybody think what model I would use for
> forgot_password and reset_password. I have a user model that has a
> password as a field. I do not really want to have a password model
> since I guess this is supposed to map to a password table in the
> database.
>
>
> What does everybody think. As you can see this is more of a
> philosophical than a technical question.
> Looking forward to some interesting replies.
>
> Anthony
>
>
I would create a PasswordRemindersController.

    * ''new'' action provides a form for the user to enter their
username
      and/or email, or something.
    * ''create'' action sends them an email with a reset
password and
      redirects to ''show'' action.
    * ''show'' action simply gives a message that the email has
been sent
      and that they should check for it.

The ''show'' action could be eliminated if you wanted the
''create'' to just
show the message, but convention dictates that POST and PUTS redirect on
success, otherwise if someone started reloading that page, it would keep
resetting their password to something else and sending another email.

As Michael pointed out, there is absolutely no need for a 1 to 1
correlation between controllers -> models -> tables. This is a classic
example of a RESTful controller with no need for a corresponding model.