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
[email protected] 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
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
[email protected] 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.