andrea.raimondi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-25 07:04 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
andrea.raimondi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
andrea.raimondi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-26 06:35 UTC
Re: Problem with rhtml
Chris T wrote:> It''s basically saying @gigolos is nil. Have a look in your controller > and check that it''s being assigned properlySorry if I sound noob in RoR, but I am :D How can I assign @gigolos in servicegigolos_controller.rb ? Should I write something like: @gigolos = new Gigolo() ? Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
andrea.raimondi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> 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 :D > > 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---