Rey
2006-Apr-29 17:33 UTC
[Rails] can i alter the _form.rhtml without have troubles to validat
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
--
Posted via http://www.ruby-forum.com/.
Mike Garey
2006-Apr-29 18:08 UTC
[Rails] can i alter the _form.rhtml without have troubles to validat
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 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>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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060429/bda69a65/attachment.html