# RuntimeError in Recipe#edit

**URL:** <https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838>\
**Category:** Rails\
**Created:** [May 7, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838 "2006-05-07T12:28:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 7, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/1 "2006-05-07T12:28:55Z")

</div>

I have tried to learn ruby on rails from scratch by going into a  
tutorial at the following website.

[http://instantrails.rubyforge.org/tutorial/index.html](http://instantrails.rubyforge.org/tutorial/index.html)

I followed the suggestions and encountered 3 problems so far.

1. Couldn’t start the Apache server. Error message “Port 80 was used by  
some other process.” I over-came the problem by going

into configuration and change the port to 4001.  
2. I couln’t connect to my localhost using the MySQL-Front. I overcame  
the problem by following the explanation in one

website and run RegEdit and changed some setting in the Windows  
Registration.  
3. I copied and pasted the codes for edit.rhtml, and run the example and  
found that text boxes were not filled with the

desired fields, but the source codes instead. I deleted every thing and  
re-installed every thing, and came to the same

problems in “Edit”.

The error message is now as follows:

RuntimeError in Recipe#edit  
Showing app/views/recipe/edit.rhtml where line #8 raised:

Called id for nil, which would mistakenly be 4 – if you really wanted  
the id of nil, use object\_id

Extracted source (around line #8):

5:   
6:

# Edit Recipe
  
7:  
8:   
9: \<input id=“recipe\_id” name=“recipe[id]” size=“30”  
10: type=“hidden” value=“\<%= @recipe.id %\>” /\>  
11: 

**Title**

It appears that @recipe is null.

Any assistance will be appreciated.

Regards

Ling

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 7, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/2 "2006-05-07T14:10:02Z")

</div>

On 5/7/06, Ling [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> into configuration and change the port to 4001.
> 
> Extracted source (around line #8):
> 
> Any assistance will be appreciated.
> 
> Regards
> 
> Ling

What URL were you using when you got this error? The URL will tell you  
the  
id of the recipe you are trying to edit. For example if the URL was :

[http://127.0.0.1:3000/recipe/edit/2](http://127.0.0.1:3000/recipe/edit/2)

Then you would be trying to edit the recipe with id=2. Once you know the  
id,  
go look at your database. Do you have a recipe with that id?

If so then there is something wrong with your controller because it  
should  
be setting @recipe.

Also, Instant Rails comes with a copy of the cookbook application  
preinstalled. Can you run this one? If so, you can always compare your  
source code with that.

Curt

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 7, 2006, 3:24pm UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/3 "2006-05-07T15:24:29Z")

</div>

Thanks for your reply.

I first clicked on â??[http://localhost:3000/recipe/listâ](http://localhost:3000/recipe/list%C3%A2)? that gave me the  
display, in website called â??[http://localhost:3000/recipe/listâ](http://localhost:3000/recipe/list%C3%A2)?

Then I clicked on one of the items, say, the first one in the grid.

That gave a url of [http://localhost:3000/recipe/show/1](http://localhost:3000/recipe/show/1)

So far, so good.

Then I clicked on the â??Editâ? button at the bottom:

That gave a url of [http://localhost:3000/recipe/edit/1](http://localhost:3000/recipe/edit/1)

Together with the error message as follows:

## RuntimeError in Recipe#edit Showing app/views/recipe/edit.rhtml where line #8 raised: Called id for nil, which would mistakenly be 4 – if you really wanted the id of nil, use object\_id Extracted source (around line #8): 5: 6:

# Edit Recipe
  
7:  
8:   
9: \<input id=“recipe\_id” name=“recipe[id]” size=“30”  
10: type=“hidden” value=“\<%= @recipe.id %\>” /\>  
11: 

**Title**  
  
RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace  
#{RAILS\_ROOT}/app/views/recipe/edit.rhtml:8  
Request  
Parameters: {“id”=\>“1”}  
Show session dump

flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

p.s.

The html codes for Edit from \<Form â?¦ to in both â??cookbookâ? and  
â??cookbook2â? are almost identical. Even after I amended the codes to be  
identical with the pre-installed, the problem persisted.

Regards,

Ling.

Curt H. wrote:

> On 5/7/06, Ling [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > into configuration and change the port to 4001.
> > 
> > Extracted source (around line #8):
> > 
> > Any assistance will be appreciated.
> > 
> > Regards
> > 
> > Ling
> 
> What URL were you using when you got this error? The URL will tell you  
> the  
> id of the recipe you are trying to edit. For example if the URL was :
> 
> [http://127.0.0.1:3000/recipe/edit/2](http://127.0.0.1:3000/recipe/edit/2)
> 
> Then you would be trying to edit the recipe with id=2. Once you know the  
> id,  
> go look at your database. Do you have a recipe with that id?
> 
> If so then there is something wrong with your controller because it  
> should  
> be setting @recipe.
> 
> Also, Instant Rails comes with a copy of the cookbook application  
> preinstalled. Can you run this one? If so, you can always compare your  
> source code with that.
> 
> Curt

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 8, 2006, 5:32am UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/4 "2006-05-08T05:32:39Z")

</div>

Are you able to run the preinstalled version of cookbook? If yes, then  
there’s got to be some subtle difference between you version and it  
(either  
in the code, or in the database).

Curt

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 8, 2006, 6:38am UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/5 "2006-05-08T06:38:52Z")

</div>

Curt H. wrote:

> Are you able to run the preinstalled version of cookbook? If yes, then  
> there’s got to be some subtle difference between you version and it  
> (either  
> in the code, or in the database).
> 
> Curt

Thanks. Curt.

I tried the pre-installed “cookbook” with the exisitng data.

I was able to create new categories, new recipes, and edit and delete.  
No problems.

I removed the “cookbook2” database and re-created the database, taking  
care to see the tables and fields are the same as those in “cookbook”

I copied the whole folder App from “cookbook” to “cookbook2” and so the  
codes are identical.

With the empty database, I now tried to display the recipes (none  
entered as yet), and an error message appeared.

So I load the website to enter 3 categories successfully.

I then entered into the web page to create a new recipe. The page loaded  
successfully with 3 items in the drop-down list for categories. I  
entered data into the text boxes and text-area, and selected one item of  
category from the drop-down and hit the “Create” button.

Unable to save data.

Errors encountered. Same as when I tried to display the recipe when  
there were none.

Please advise what to do from now.

Regards,

Ling.

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 8, 2006, 10:04am UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/6 "2006-05-08T10:04:58Z")

</div>

Great!

---

<div class="post-metadata">

**Author:** ![Ling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Ling](https://www.ruby-forum.com/u/Ling)\
**Post date:** [May 8, 2006, 7:16am UTC](https://www.ruby-forum.com/t/runtimeerror-in-recipe-edit/59838/7 "2006-05-08T07:16:37Z")

</div>

Curt H. wrote:

> Are you able to run the preinstalled version of cookbook? If yes, then  
> there’s got to be some subtle difference between you version and it  
> (either  
> in the code, or in the database).
> 
> Curt

Hi, Curt

I found my mistake in the database setting.

The field “title” in the table [recipes] doesnot allow null and I set  
the default to [null].

Once I corrected this mistake, the application is running.

Thanks for your advice that led me me to discover the mistake.

Now, I can proceed to a new tutorial.

Regards,

Ling.
