Forum: Ruby on Rails can i alter the _form.rhtml without have troubles to validat

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F48b1167605be400c501f6ceb808c533?d=identicon&s=25 Rey (Guest)
on 2006-04-29 19:33
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' %>
<!--[form:catelemento]-->

<p><label for="catelemento_Comandancia">Comandancia</label><br/>

<select id="catelemento_Comandancia" name="catelemento[Comandancia]">
    <%for koman in @komandancias %>
            <option value="<%= koman.id %>"><%= koman.Nombre %></option>
    <% end %>
</select>


<p><label for="catelemento_Clave">Clave</label><br/>
<%= text_field 'catelemento', 'Clave'  %></p>

<p><label for="catelemento_Nombre">Nombre</label><br/>
<%= text_field 'catelemento', 'Nombre'  %></p>



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
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2006-05-03 19:09
(Received via mailing list)
On 4/29/06, Rey <zyon13@hotmail.com> 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
> </select>
instead of the above, you could use:

<select id="catelemento_Comandancia" name="catelemento[Comandancia]">
    <%= options_from_collection_for_select(@komandancias, 'id',
'nombre', {:prompt => "Please select a value"}) %>
</select>

<p><label for="catelemento_Clave">Clave</label><br/>
> <%= text_field 'catelemento', 'Clave'  %></p>
>
> <p><label for="catelemento_Nombre">Nombre</label><br/>
> <%= text_field 'catelemento', 'Nombre'  %></p>


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
This topic is locked and can not be replied to.