# Problem with rhtml

**URL:** <https://www.ruby-forum.com/t/problem-with-rhtml/69882>\
**Category:** Rails\
**Created:** [September 25, 2006, 9:09am UTC](https://www.ruby-forum.com/t/problem-with-rhtml/69882 "2006-09-25T09:09:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 25, 2006, 9:09am UTC](https://www.ruby-forum.com/t/problem-with-rhtml/69882/1 "2006-09-25T09:09:33Z")

</div>

Hello.

I have this source rhtml file:

# New service\_gigolo

\<%= start\_form\_tag :action =\> ‘create’ %\>  
  
\<%for gigolo in @gigolos%\>  
  
\<%=gigolo.column(name)%\>  
\<%end%\>  
  
\<%= render :partial =\> ‘form’ %\>  
\<%= submit\_tag “Create” %\>  
\<%= end\_form\_tag %\>

\<%= link\_to ‘Back’, :action =\> ‘list’ %\>

but when I execute it, I get the following:

NoMethodError in Service\_gigolos#new

Showing app/views/service\_gigolos/new.rhtml where line #5 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 #5):

2:  
3: \<%= start\_form\_tag :action =\> ‘create’ %\>  
4:   
5: \<%for gigolo in @gigolos%\>  
6:   
\<%=gigolo.column(name)%\>  
7: \<%end%\>  
8:

Can you suggest where my problem lies? Maybe I’m trying to  
reference a non-existing data table in that context?

Any pointers?

TIA,

Andrew

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 25, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/problem-with-rhtml/69882/2 "2006-09-25T15:38:29Z")

</div>

removed\_email\_address@domain.invalid wrote:

> \<%=gigolo.column(name)%\>  
> NoMethodError in Service\_gigolos#new  
> 3: \<%= start\_form\_tag :action =\> ‘create’ %\>  
> Any pointers?
> 
> TIA,
> 
> Andrew
> 
> >

It’s basically saying @gigolos is nil. Have a look in your controller  
and check that it’s being assigned properly

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 26, 2006, 8:39am UTC](https://www.ruby-forum.com/t/problem-with-rhtml/69882/3 "2006-09-26T08:39:43Z")

</div>

Chris T wrote:

> It’s basically saying @gigolos is nil. Have a look in your controller  
> and check that it’s being assigned properly

Sorry if I sound noob in RoR, but I am 😃

How can I assign @gigolos in servicegigolos\_controller.rb ?

Should I write something like:

@gigolos = new Gigolo() ?

Andrew

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 26, 2006, 10:38am UTC](https://www.ruby-forum.com/t/problem-with-rhtml/69882/4 "2006-09-26T10:38:14Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Should I write something like:
> 
> @gigolos = new Gigolo() ?
> 
> Andrew
> 
> >

Rather depends what you’re trying to do (can’t exactly work it out). But  
the correct ruby code (assuming your model is called Gigolo) is:  
@gigolo = Gigolo.new (this will create a new instance variable,  
@gigolo, of class Gigolo). But best advice I can give is to get Dave  
Thomas’s Agile Web D. with Rails as soon as poss. Although the  
screencasts make Rails look ike you can dive right in there without  
understanding what you’re writing, as an ex-newb myself, I wasted a lot  
of time doing that, before spending some time getting to understand what  
I was writing.
