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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
antonio rodriguez (Guest)
on 2006-05-18 15:56
(Received via mailing list)

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)


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="<%= %>">
29: <%= %>
30: </option>

Why the sentences in the model

Some ideas?


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.