I''m new here- here''s the background on my question: * I''m building a cart * I''m also reading "Agile Rails Development" * Controller is "store_controller.rb" * View "index" displays products, only the image, no other detail * My desired functionality is that the user clicks the image in the index view and gets the view "details", which is where the product can be added to the cart. I don''t have a lot of experience with the MCV model that Rails is all about, so I''m having trouble getting the conceptual idea of what I need to do to pull this off. My questions are: * What definitions and methods to I need to put in the controller "store_controller.rb", the model "product.rb" and * How do I make them work together with the views "index" and "details"? Thank you so much for your help, I''d rather learn how to think about this correctly and get a level of elegance in my code than beat my head against the wall making something "work". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The views correspond to "actions" (methods) in the controller. Your controller (product_controller.rb) will look something like: def index @products = Product.find(:all) end def details @product = Product.find(params[:id]) end And your views will be in app/views/product/. When a user requests product/index, the application will try to render it with views/product/index.rhtml. Your index.rhtml might look like: <% @products.each do | product | -%> <%= link_to image_tag(product.image, {:alt => product.name}), :action => :details, :id => product.id)-%> <% end %> Is that what you meant? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes. :-) Thank you! jdswift wrote:> The views correspond to "actions" (methods) in the controller. Your > controller (product_controller.rb) will look something like: > > def index > @products = Product.find(:all) > end > > def details > @product = Product.find(params[:id]) > end > > And your views will be in app/views/product/. > When a user requests product/index, the application will try to render > it with views/product/index.rhtml. Your index.rhtml might look like: > > <% @products.each do | product | -%> > <%= link_to image_tag(product.image, {:alt => product.name}), > :action => :details, :id => product.id)-%> > <% end %> > > Is that what you meant?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---