Forum: Ruby on Rails validates_presence_of

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.
ss (Guest)
on 2006-04-19 16:26
Hi, having a few problems working out whats kicking off,

im using validates_presence_of :title in a models class

this seemed to work fine untill I used a custom new.rhtml

error message I am gaining is

 NoMethodError in Recipe#create

Showing app/views/recipe/new.rhtml where line #15 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

12:  <p>
13:  <b>Category:</b><br/>
14:  <select name="recipe[category_id]">
15:  <% @categories.each do |category| %>
16:  <option value="<%= %>">
17:  <%= %>
18:  </option>

the def create controller looks somthing like this

        def create
		@recipe =['recipe']) =
			redirect_to :action => 'list'
			render_action 'new'

any suggestions to where im going wrong?
Charlie B. (Guest)
on 2006-04-19 16:36
(Received via mailing list)
It looks like you need to get @categories in your create method so that
it will be available in your template.
This topic is locked and can not be replied to.