Problem with rhtml

Hello.

I have this source rhtml file:

<h1>New service_gigolo</h1>

<%= start_form_tag :action => 'create' %>
  <select>
    <%for gigolo in @gigolos%>
      <option value="<%=gigolo.column(id)%>">
<%=gigolo.column(name)%></option>
   <%end%>
  </select>
  <%= 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: <select>
5: <%for gigolo in @gigolos%>
6: <option value="<%=gigolo.column(id)%>">
<%=gigolo.column(name)%></option>
7: <%end%>
8: </select>

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

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

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 :smiley:

How can I assign @gigolos in servicegigolos_controller.rb ?

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 Development 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.