I’m running rails 2.3.8 and restful_authentication and I find the
error messages generated in the by_password.rb are not appearing,
instead I get the user-hostile {{attribute}} {{message}} messages.
I’ve tried and tried to figure a fix and, aside from discarding
restful_authentication (which I may do, at a later date) I can’t solve
the problem. Any suggestions?
Thanks, but I’ve gone down this route already. The key thing to note:
all
model errors in my app are printed correctly except one: the
restful_authentication signup step. For example, here is my en.yml:
en:
use_only_lets:
use only letters, numbers
passwordpresent:
password required
confirmation:
password doesn’t match confirmation
passwordlength:
password must be 6-40 characters long
activerecord:
errors:
template:
body: There were problems with the following fields
header:
one: 1 error prohibited this %{model} from being saved
other: “%{count} errors prohibited this %{model} from being
saved”
messages:
inclusion: “is not included in the list”
exclusion: “is reserved”
invalid: “is invalid”
confirmation: “doesn’t match confirmation”
accepted: “must be accepted”
empty: “can’t be empty”
blank: “can’t be blank”
too_long: “is too long (maximum is %{count} characters)”
too_short: “is too short (minimum is %{count} characters)”
wrong_length: “is the wrong length (should be %{count}
characters)”
taken: “has already been taken”
not_a_number: “is not a number”
greater_than: “must be greater than %{count}”
greater_than_or_equal_to: “must be greater than or equal to
%{count}”
equal_to: “must be equal to %{count}”
less_than: “must be less than %{count}”
less_than_or_equal_to: “must be less than or equal to
%{count}”
odd: “must be odd”
even: “must be even”
bad_email: “Email should look like an email address”
bad_login: “Use only letters and numbers for your user name”
bad_name: “Use only legal characters in your name”
To summarize: In my rails 2.3.8 app, which uses restful_authentication,
all
model error messages (and there are a lot) work exactly as desired
except
for the scenario where a new user is signing up for the first time.
Unfortunately this leaves potential new users with a really bad
impression.
For example, if the new user fails to enter a matching password -
password
confirmation, or makes any other entry error (no password, no login,
etc),
the message is like the following:
1 error prohibited this user from being saved
There were problems with the following fields
{{attribute}} {{message}}
The {{attribute}}{{message}} isn’t translated. And yes I know to use %{}
and
not {{}} in en.yml. Clearly there is something I am doing wrong but
I’ve
exhausted my ideas. Last I tried was as follows, which is an excerpt
from
by_password.rb:
module Authentication
module ByPassword
# Stuff directives into including module
def self.included(recipient)
recipient.extend(ModelClassMethods)
recipient.class_eval do
include ModelInstanceMethods
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :password,
For example, if the new user fails to enter a matching password - password
confirmation, or makes any other entry error (no password, no login, etc),
the message is like the following:
The {{attribute}}{{message}} isn’t translated. And yes I know to use %{} and
not {{}} in en.yml. Clearly there is something I am doing wrong but I’ve
exhausted my ideas.Last I tried was as follows, which is an excerpt from
by_password.rb:
validates_presence_of :password,
:message=>I18n.t(:passwordpresent), :if => :password_required?
Not relevant anymore, but for good measure: if you use I18n.t in a
class context like that, IIRC it will always use the default locale in
production (since the class isn’t reloaded for every request).
Instead, you just specify the symbol (:message => :passwordpresent)
and make sure to put the translation key in the expected place
(somewhere under activerecord.errors I believe).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.