Following a tutorial here and I had it pointed out to me that it may be a slightly older version (Agile web development v2) so I''m hoping my problem is just sytax that one of the gurus here can point out... I have a view called store/index.rhtml; it looks like this - <h1>The store catalog</h1> <% for products in @products -%> <div class="entry"> <%= image_tag(product.image_url) %> <h3><%= h(product.title) %> <span class="price"><%= product.price %></span> </div> <% end %> It should just list some sample product data. But it tells me: undefined local variable or method `product'' for #<#<Class:0x275be4c>:0x275be24> Yet, in my admin view a call regarding ''product works fine: e.g. <%= product.image_url %> My store controller looks like: class StoreController < ApplicationController def index @products = Product.find_products_for_sale end end Any advise? I''d be very thankful. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hassan Schroeder
2008-Dec-21 17:17 UTC
Re: But, my local variable ''product'' is defined!!
On Sun, Dec 21, 2008 at 9:08 AM, Ryan Ororie <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Following a tutorial here and I had it pointed out to me that it may be > a slightly older version (Agile web development v2) so I''m hoping my > problem is just sytax that one of the gurus here can point out...When posting something like this, it''s always a good idea to mention the version of Rails you''re using :-) but...> I have a view called store/index.rhtml; it looks like this -> <% for products in @products -%> > <div class="entry"> > <%= image_tag(product.image_url) %>> It should just list some sample product data. But it tells me: > > undefined local variable or method `product'' for > #<#<Class:0x275be4c>:0x275be24>As it should -- where do you see the variable ''product'' defined in the above code? You can fix by changing to `for product in @products` which also reads properly -- one ''product'' from a collection of ''@products''. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---