Hello everyone, I have a problem while opening something like /main/show/1 Here is the template for show.rhtml <% for name in @names %> <div> <h2><%= name.full_name %></h2> </div> <% end %> And here is the code specific to the show on the main_controller.rb def show name = Name.find(params[:id]) end And here is the error im getting. 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 Any idea on what the problem might be? Any help would be great, thanks! -- Posted via http://www.ruby-forum.com/.
Guest wrote:> Hello everyone, I have a problem while opening something like > /main/show/1 > > Here is the template for show.rhtml > > <% for name in @names %> > <div> > <h2><%= name.full_name %></h2> > </div> > <% end %> > > And here is the code specific to the show on the main_controller.rb > > def show > name = Name.find(params[:id]) > end > > And here is the error im getting. > > 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 > > Any idea on what the problem might be? Any help would be great, thanks!In your template you reference @names. In your controller you do not define @names, so you get a nil object error - the @names object doesn''t exist. You probably want to cut the first and last lines of your show.rhtml since you are only showing one name each time, not the whole array of names. -- Ray
Ray Baxter wrote:> You probably want to cut the first and last lines of your show.rhtml > since you are only showing one name each time, not the whole array of > names.Alright I tried that and got an error: undefined local variable or local method ''name'' I have no idea why Im having so much trouble with this, it seems so simple yet I cant get it to work. -- Posted via http://www.ruby-forum.com/.
Guest wrote:> Ray Baxter wrote: >> You probably want to cut the first and last lines of your show.rhtml >> since you are only showing one name each time, not the whole array of >> names. > > Alright I tried that and got an error: > > undefined local variable or local method ''name'' > > I have no idea why Im having so much trouble with this, it seems so > simple yet I cant get it to work.I have this same problem, and it doesn''t seem like it''s been answered here. Does anyone have an idea of why this doesn''t work? I can''t seem to get rid of the scaffolding column loop system so I can just show certain elements as I wish and style them as I wish. Any ideas? Thanks, Dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---