- I''m building an store app that include a product catalog, details page, and cart. - I''m attempting to put them in the same layout using partials. - Product catalog is the index action of the store controller - I can get the cart on the page by adding @cart = find_cart to the "def index" block. If there''s not a cart already, find_cart creates one I can''t get the details view to be on the index page layout. I need @product for the details view but I can''t just add "@product Product.find(params[:id]) to the "def index" block because the I''ll get a RecordNotFound as there''s not a product selected intially. What should I do to get around this problem? And while I''m at it, whats a better way to say "the ''def index'' block"? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m not sure I 100% understand the problem, but here is a couple of solutions Conditionally check if you have params[:id] set before calling Product.find to avoid generating the error? @product= Product.find(params[:id]) unless params[:id].nil? Or do a find(:all) so it returns an empty result set, that opens you up to having multiple products returned though which you probably wouldn''t want: @products = Product.find(:all, :conditions=>[''id=?,params[:id]]) As for def index, maybe just the index action? Not sure what the common practice is here myself. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, that makes sense and what I was actually thinking initally, but it doesn''t really help me because of this: Clicking on the product in the catalog invokes the "view_details" action, which is fine if it not a partial (i.e. path in the browser is /store/view_details/5). The problem is, according to my understanding so far of partials, the action in "view_details" must "redirect_to :action => :index". Because of that redirect, it appears as though the selection doesn''t persist and therefore my "view_details" (i.e. the currently selected item) never displays. So I''m starting to think that I have to store the current product selected in the session by way of something like a "Basket" (more temporary than a cart? good names are welcome) model. Does that makes sense? Or is there a better way to make my selection persist so I can display the catalog, deatails and cart all on the same page? glenn wrote:> I''m not sure I 100% understand the problem, but here is a couple of > solutions > > Conditionally check if you have params[:id] set before calling > Product.find to avoid generating the error? > @product= Product.find(params[:id]) unless params[:id].nil? > > Or do a find(:all) so it returns an empty result set, that opens you up > to having multiple products returned though which you probably wouldn''t > want: > @products = Product.find(:all, :conditions=>[''id=?,params[:id]]) > > As for def index, maybe just the index action? Not sure what the common > practice is here myself.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---