Forum: Ruby on Rails [newbie]problem when using validates*

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.
D81b718e125c403ac8511947ad621333?d=identicon&s=25 antonio rodriguez (Guest)
on 2006-05-18 13:56
(Received via mailing list)
Hi,

I have performed the cookbook tutorial. Before tailoring the views and
controllers, when I put in the model recipe.rb:

validates_uniqueness_of :title
validates_length_of :title, :within => 1...20

And I tried to introduce some new recipe without the above conditions I
got the message:

---------------------------------------------------
New recipe
1 error prohibited this category from being saved

There were problems with the following fields:

     * Name is too short (minimum is 1 characters)

Name
Back
----------------------------------------------------

So, just fine. But after tailoring the views and controller I'm not
longer able to get this, just this one:


  NoMethodError in Recipe#create

Showing app/views/recipe/new.rhtml where line #27 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each

Extracted source (around line #27):

24: <p>
25: <b>Categoria:</b><br/>
26: <select name="recipe[category_id]">
27: <% @categories.each do |category| %>
28: <option value="<%= category.id %>">
29: <%= category.name %>
30: </option>

Why the sentences in the model

Some ideas?

BR

Antonio
--
=====
Por favor, si me mandas correos con copia a varias personas,
pon mi dirección de correo en copia oculta (CCO), para evitar
que acabe en montones de sitios, eliminando mi privacidad,
favoreciendo la propagación de virus y la proliferación del SPAM. Gracias.
-----
If you send me e-mail which has also been sent to several other people,
kindly mark my address as blind-carbon-copy (or BCC), to avoid its
distribution, which affects my privacy, increases the likelihood of
spreading viruses, and leads to more SPAM. Thanks.
=====
This topic is locked and can not be replied to.