Can i alter the _form.rhtml without have troubles to validat


#1

hello my name is reynaldo

and i have a problem

i alter the _form.rhtml to display a select option in the place a simple
text_box, and the application work very well, but in the moment that i
apply a validation in the model i get a error.

the code is the next

in the controller:

def new
@catelemento = Catelemento.new
@komandancias = Catcomandancia.find(:all)
end

in the _form.rhtml

<%= error_messages_for ‘catelemento’ %>

Comandancia
<%for koman in @komandancias %> <%= koman.Nombre %> <% end %>

Clave
<%= text_field 'catelemento', 'Clave' %>

Nombre
<%= text_field 'catelemento', 'Nombre' %>

in the model
class Catelemento < ActiveRecord::Base
validates_presence_of :Nombre
end


the case is the next:

if i remove the validation : the application works

if i remove the selecet option : the application works

but i need both characteristics

if any person can help me, i’ll thank you so much


#2

On 4/29/06, Rey removed_email_address@domain.invalid wrote:

hello my name is reynaldo

and i have a problem

i alter the _form.rhtml to display a select option in the place a simple
text_box, and the application work very well, but in the moment that i
apply a validation in the model i get a error.

what is the error that you get?

the code is the next

in the _form.rhtml

instead of the above, you could use:

<%= options_from_collection_for_select(@komandancias, 'id', 'nombre', {:prompt => "Please select a value"}) %>

Clave
> <%= text_field 'catelemento', 'Clave' %>

> >

Nombre
> <%= text_field 'catelemento', 'Nombre' %>

just a suggestion: use lower case for all your attribute names… ie
instead
of ‘Clave’, use ‘clave’. You should only use leading capitals for class
names (make sure the rows in your database also use lowercase names)

Mike