I know what I am trying to do would seem laughably easy to some, but
pray accept my excuses for still being nothing more than a newbie where
rails is concerned. It seems there is so much to learn. And with rails
it's always not about doing it, but doing it easily and meaningfully,
i.e. I'm asking how to do it the RIGHT way.
Now, I am having a very simple User/Session model (implemented using
Authlogic). In fact it is so simple, that all the functionality
regarding profile editing is put on ONE page. I'd like the user to be
able to set some details AND to be able to change their password. In
case the user desires to change their password, i.e. does NOT leave the
password field blank, they must be required to enter their current
password (sounds logical enough to me) in another field.
However, there are a couple of problems I am experiencing with this
Firstly, how could I tell the User model to forget about the password
fields and NOT save them if they are empty (I know how to validate them
but that alone doesn't seem to do it) and so Authologic wouldn't
Secondly, is there any way to validate that the entered password in the
`password_check` field matches the current one, but do it using custom
validation callbacks (i.e. in the model, not in the controller)? I don't
see how one could have access to the params hash from within the model
validation methods (and it doesn't seems right to me to do so) so should
one use virtual attributes to do the check?!
Thirdly, even if all that validation was done in the controller (i.e. if
it is not possible to be done in the model), does anyone know how I am
to compare the entered password and the current one for it is stored in
encrypted form. There must be some method in Authologic that should be
able to do just that (i.e. not reviling the password, but comparing an
entered password against the current one).
And finally, is there any way to add errors to an ActiveRecord object
from within the controller (not the model) so as to be able to show them
along with the other validation errors if I can't make that validation
in the model?
Thank you awfully much!
...and sorry for the bunch of words but it's incredibly hard to express
extremely simple things simply.