Validation highlighting on non-scaffold fields


#1

Hi all,

I’m new to rails.

I have created a bunch of CRUD code using scaffolds.
I had to add code to the default output to account for
fields that establish the relationships between tables.

Everything works well, including the validation of the
fields I added. However, I can’t get the highlighting
to work for my fields when they fail validation and the
view is redisplayed.

Here is an example snippet from _form.rhtml:

Number
<%= text_field 'account', 'number' %>
Broker
Choose <% for broker in @brokers %> <%=broker.name%> <% end %>

I think if I used the select helper it would work, but I
can’t think of a way to inject my “fake” row of “0, Choose”
as a Broker that forces the user to pick a value from the
dropdown (he legit values are all in the @brokers list).

Any ideas?

-Shane


#2

Shane Bouslough wrote:

I think if I used the select helper it would work, but I
can’t think of a way to inject my “fake” row of “0, Choose”
as a Broker that forces the user to pick a value from the
dropdown (he legit values are all in the @brokers list).

Any ideas?

From the rails docs for the select helper…

:prompt - set to true or a prompt string. When the select element
doesnâ??t have a value yet, this prepends an option with a generic prompt
â?? “Please select” â?? or the given prompt string.

_Kevin


#3

Kevin O. wrote:

:prompt - set to true or a prompt string. When the select element
doesnâ??t have a value yet, this prepends an option with a generic prompt
â?? “Please select” â?? or the given prompt string.

That cleans up my code a lot, thanks. I also had an invalid
call to errors.ad() which was keeping my field from being
highlighted.

-Shane