High Level MCV Question

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".

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?

Yes. :slight_smile:

Thank you!

jdswift wrote: