magic6435-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-14 17:01 UTC
NoMethodError after refresh?
This is strange. I''m working on a simple comment system but it has a fit when displaying the user names after the first time the page is loaded. so if i start the webserver then go to the page everything works fine but if i then refresh i get this error. if i remove the user.login it works fine always. Also i have other places in the site that show the Mode.user.login and they work fine ActionView::TemplateError (You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include?) on line #12 of app/ views/bids/show.html.erb: 11: <% @bid.comments.each do |comment| %> 12: <%= comment.user.login %> 13: <%= simple_format(comment.comment) %> 14: <% end %> 15: Any one got an idea of why this is happening? if i set the dev env to cache classes then it has no problems.. config.cache_classes = true Thanks for any help. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Typically this means you have confused rails'' dependency system. One way you can achieve that is using require to load your application classes instead of require_dependency. I wrote a blog post about that not too long ago. You should be able to find it if you google for "required or not" Fred Sent from my iPhone On 14 Nov 2008, at 17:01, "magic6435-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <magic6435-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > This is strange. I''m working on a simple comment system but it has a > fit when displaying the user names after the first time the page is > loaded. so if i start the webserver then go to the page everything > works fine but if i then refresh i get this error. if i remove the > user.login it works fine always. Also i have other places in the site > that show the Mode.user.login and they work fine > > ActionView::TemplateError (You have a nil object when you didn''t > expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include?) on line #12 of app/ > views/bids/show.html.erb: > 11: <% @bid.comments.each do |comment| %> > 12: <%= comment.user.login %> > 13: <%= simple_format(comment.comment) %> > 14: <% end %> > 15: > > > Any one got an idea of why this is happening? if i set the dev env to > cache classes then it has no problems.. > config.cache_classes = true > > Thanks for any help. > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
magic6435-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-15 15:58 UTC
Re: NoMethodError after refresh?
Ah thanks ill give that a try. On Nov 14, 12:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Typically this means you have confused rails'' dependency system. One > way you can achieve that is using require to load your application > classes instead of require_dependency. I wrote a blog post about that > not too long ago. You should be able to find it if you google for > "required or not" > > Fred > > Sent from my iPhone > > On 14 Nov 2008, at 17:01, "magic6...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <magic6...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > This is strange. I''m working on a simple comment system but it has a > > fit when displaying the user names after the first time the page is > > loaded. so if i start the webserver then go to the page everything > > works fine but if i then refresh i get this error. if i remove the > > user.login it works fine always. Also i have other places in the site > > that show the Mode.user.login and they work fine > > > ActionView::TemplateError (You have a nil object when you didn''t > > expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.include?) on line #12 of app/ > > views/bids/show.html.erb: > > 11: <% @bid.comments.each do |comment| %> > > 12: <%= comment.user.login %> > > 13: <%= simple_format(comment.comment) %> > > 14: <% end %> > > 15: > > > Any one got an idea of why this is happening? if i set the dev env to > > cache classes then it has no problems.. > > config.cache_classes = true > > > Thanks for any help.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---