Hi all, I''ve created an app that has posts with string "title" and text "content". I''m getting the following error when adding this loop. Any idea? NameError in Posts#index Showing */Users/bradwrage/webapps/blog/app/views/posts/index.html.erb* where line *#7* raised: undefined local variable or method `post'' for #<#<Class:0x10bf2d620>:0x10c058798> Extracted source (around line *#7*): 4: 5: <% @posts.each do |status| %> 6: <div class="post"> 7: <strong><%= post.title %></strong> 8: </div> 9: 10: <% end %> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AS41BIVwtdYJ. For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Oct 18, 2012 at 9:38 AM, wragen22 <bradwrage-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Extracted source (around line #7): > > 4: > 5: <% @posts.each do |status| %> > 6: <div class="post"> > 7: <strong><%= post.title %></strong> > 8: </div> > 9: > 10: <% end %>Took me all of 0.00000000000000000000000000000000000000001 seconds to notice that you have @posts.each o |status| instead of @posts.each do |post| which means you haven''t even told it that post should be the variable in that closure, status is the current. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
you loop through all @posts, but your object is called "status" - change "status" to "post" and everything will work.. Am Donnerstag, 18. Oktober 2012 16:38:03 UTC+2 schrieb wragen22:> > Hi all, > > I''ve created an app that has posts with string "title" and text "content". > > I''m getting the following error when adding this loop. Any idea? > > NameError in Posts#index > > Showing */Users/bradwrage/webapps/blog/app/views/posts/index.html.erb* where > line *#7* raised: > > undefined local variable or method `post'' for #<#<Class:0x10bf2d620>:0x10c058798> > > Extracted source (around line *#7*): > > 4: > 5: <% @posts.each do |status| %> > 6: <div class="post"> > 7: <strong><%= post.title %></strong> > 8: </div> > 9: > 10: <% end %> > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vaEb1SQg7aIJ. For more options, visit https://groups.google.com/groups/opt_out.
Hello, Try to change post.title to status.title. You say that for every post do and name it status. Roelof Op donderdag 18 oktober 2012 16:38:03 UTC+2 schreef wragen22 het volgende:> Hi all, > > I''ve created an app that has posts with string "title" and text "content". > > I''m getting the following error when adding this loop. Any idea? > > NameError in Posts#index > > Showing */Users/bradwrage/webapps/blog/app/views/posts/index.html.erb* where > line *#7* raised: > > undefined local variable or method `post'' for #<#<Class:0x10bf2d620>:0x10c058798> > > Extracted source (around line *#7*): > > 4: > 5: <% @posts.each do |status| %> > 6: <div class="post"> > 7: <strong><%= post.title %></strong> > 8: </div> > 9: > 10: <% end %> > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vu-d1BtyJCcJ. For more options, visit https://groups.google.com/groups/opt_out.