i am using the normal rails error checking that comes with scaffold.
Now I a password_confirmation field in my form - which is not in my
database
the confirmation checking works perfect and a text will be shown in the
error box if the 2 password fields are not equal.
My problem is, that the border around the password_confirmation field
will not get red - when the password_confirmation field throws an error.
View the html source of the generated html when an error is thrown and
write down “id” of the element that you want to color red and then edit
your .css accordingly.
(If you are using the scaffolding generator then most likely the .css
you are linking to is scaffold.css)
View the html source of the generated html when an error is thrown and
write down “id” of the element that you want to color red and then edit
your .css accordingly.
(If you are using the scaffolding generator then most likely the .css
you are linking to is scaffold.css)
I think, you should check your layouts *.rhtml file. In the header must
be the following code:
<%= stylesheet_link_tag ‘scaffold’, :media => ‘all’ %>
(if you use scaffold.css)
If you use your owen .css -file, include following code:
.fieldWithErrors {
padding: 2px;
border: 2px solid red;
display: table;
}
(in to *.css file)
This is excactly what I hate on rails, all answers are different - and
none of them is working. You cant solve the problem - because I tap into
fog right now on a so easy thing that was done in asp in seconds. but
with the scaffold thing - I dont know whats going on in the background.
yes, I use the scaffhold css
yes, I inserted <%= stylesheet_link_tag ‘scaffold’, :media => ‘all’
%>
the field that is not red - is a field that is not in the database -
it is a password_confirmation field. the error text is correct and the
confirmation works
<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>
my css class ‘input’ is ok - i use it on all other fields too
confirmation works
<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>
4) my css class ‘input’ is ok - i use it on all other fields too
You see, it work like this:
If you use built-in form helpers (e.g. text_field helper), they check if
the
model instance for which you render that field has errors, and if so, it
will
wrap the generated field HTML in DIV with some class (fieldWithErrors,
but
I’m not sure).
Then, the validates_confirmation_of is designed to add validation error
for
the attribute itself, not it’s “_confirmation” brother (e.g. for
“password”,
not for “password_confirmation”).
So, when text_field for password_confirmation is produced, it find no
errors
for that field, so no “red border” is displayed around that field.
The same problems I had long ago, when I designed validation for
associated
objects. E.g. Product should have a Category associated. I used to write
class Product < ActiveRecord::Base
belongs_to :category
validates_presence_of :category
end
In the product edit I used to create a select for category_id attribute
which
didn’t outlined this select if there was no category specified. The
right
solution was to do “validates_presence_of :category_id” (and then, if
you
wish to, do “validates_associated :category”).
Solutions are:
Leave everything as it is. Actually, It could be a problem with
password
field, not with password_confirmation field.
Design new validation that will check if attributes are equal and add
error
to password_confirmation instead of password.
Design a custom text_field helper for “password_confirmation”, that
will
check if “password” field has errors and outline itself then.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.