Hey guys, I am a noob, so hopefully this problem has an easy solution. I am building a simple shopping cart with products that have product categories. I have set up my routes like the following: map.resources :product_categories do |product_categories| product_categories.resources :products end which should get me /product_categories/{:product_category_id}/ products/{:id} (for example) All of the paths seem to be working except when I click to edit a product. I am using the edit_product_category_product_path(@product_category,@product) method in the link_to. When I click to edit a product with this path, I get the following error message: product_category_product_url failed to generate from {:action=>"show", :product_category_id=>#<Product id: 2, name: "test 2", item_number: "klagkljga", price: #<BigDecimal:2363a60,''0.4323E2'', 8(8)>, description: "HEY!", created_at: "2008-07-15 00:41:02", updated_at: "2008-07-15 00:41:02", product_category_id: 1>, :controller=>"products"}, expected: {:action=>"show", :controller=>"products"}, diff: {:product_category_id=>#<Product id: 2, name: "test 2", item_number: "klagkljga", price: #<BigDecimal:236223c,''0.4323E2'',8(8)>, description: "HEY!", created_at: "2008-07-15 00:41:02", updated_at: "2008-07-15 00:41:02", product_category_id: 1>} In my products controller, I have a private method: private def load_product_category @product_category ProductCategory.find(params[:product_category_id]) end which I call in before_filter on the controller so that this instance variable is available to all actions Does anyone have any ideas? I would really appreciate it! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
anyone? On Jul 14, 9:24 pm, validkeys <kyle.da...-s5CVtH8h5JrZ3NRrNVlbw1aTQe2KTcn/@public.gmane.org> wrote:> Hey guys, > > I am a noob, so hopefully this problem has an easy solution. I am > building a simple shopping cart with products that have product > categories. > > I have set up my routes like the following: > > map.resources :product_categories do |product_categories| > product_categories.resources :products > end > > which should get me /product_categories/{:product_category_id}/ > products/{:id} (for example) > > All of the paths seem to be working except when I click to edit a > product. I am using the > edit_product_category_product_path(@product_category,@product) method > in the link_to. When I click to edit a product with this path, I get > the following error message: > > product_category_product_url failed to generate from > {:action=>"show", :product_category_id=>#<Product id: 2, name: "test > 2", item_number: "klagkljga", price: #<BigDecimal:2363a60,''0.4323E2'', > 8(8)>, description: "HEY!", created_at: "2008-07-15 00:41:02", > updated_at: "2008-07-15 00:41:02", product_category_id: > 1>, :controller=>"products"}, expected: > {:action=>"show", :controller=>"products"}, diff: > {:product_category_id=>#<Product id: 2, name: "test 2", item_number: > "klagkljga", price: #<BigDecimal:236223c,''0.4323E2'',8(8)>, > description: "HEY!", created_at: "2008-07-15 00:41:02", updated_at: > "2008-07-15 00:41:02", product_category_id: 1>} > > In my products controller, I have a private method: > > private > > def load_product_category > @product_category > ProductCategory.find(params[:product_category_id]) > end > > which I call in before_filter on the controller so that this instance > variable is available to all actions > > Does anyone have any ideas? I would really appreciate it!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How are you doing the link_to? -- 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 -~----------~----~----~----~------~----~------~--~---
Try this: edit_product_category_product_path(@product_category.id,@product) On Tue, Jul 15, 2008 at 5:14 PM, Andreh Luis < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > How are you doing the link_to? > -- > 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 -~----------~----~----~----~------~----~------~--~---
I believe you can also just do: url_for [@product_category, @product] if you have your routes set up right. I do this sort of thing all the time fo nested restful routes: <%= link_to h(@item.name), [ @category, @item ] %> On Wed, Jul 16, 2008 at 7:14 AM, Rizwan Reza <rizwanreza-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this: edit_product_category_product_path(@product_category.id,@product)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry guys, for some reason i wasn''t getting email updates that anyone had posted anything here. Let me try these out and will let you know! Thanks for your help! On Jul 16, 9:31 am, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I believe you can also just do: > > url_for [@product_category, @product] > > if you have your routes set up right. I do this sort of thing all the > time fo nested restful routes: > > <%= link_to h(@item.name), [ @category, @item ] %> > > On Wed, Jul 16, 2008 at 7:14 AM, Rizwan Reza <rizwanr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Try this: edit_product_category_product_path(@product_category.id,@product)--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---