im using <%= button_to ''Rent'', :controller => ''transaction'' , :action => ''rent'', :id => @product.id %> on ProductsController to pass an :id to a TransactionController but when searching for the product''s id def load_product @product = Product.find(:id).id end i get Couldn''t find Product with ID=id Error i tried using @product = Product.find(1).id for testint an worked, also, the URL is ok transaction/rent/1 controller/action/id BTW, how can i turn that button_to onto a link_to that works with an action outside self controller -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 November 2010 01:39, Jose tomas R. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> im using > <%= button_to ''Rent'', :controller => ''transaction'' , :action => ''rent'', > :id => @product.id %> > > on ProductsController to pass an :id to a TransactionController > > but when searching for the product''s id > > def load_product > @product = Product.find(:id).idDid you mean find(params[:id])? Also why have you got .id on the end, that means it will find the product (once that bit is working), look up the id and save it in @product. I would have expected to see just @product = Product.find(params[:id])> > BTW, how can i turn that button_to onto a link_to that works with an > action outside self controllerJust specify the controller in the link as you have done for the button. If the code you have shown is in the transaction controller/view then you do not need to specify the controller. Also have a look at the rails guide on Routes to see more sophisticated ways of specifying paths in links. On a side note it is arguably better not to put two questions in one message. The two sets of replies will get mixed up in the thread and can be difficult to follow. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
wow, that was easy to fix. it''s ".id" cause i need just the product ID thanks for your help and advice -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 November 2010 13:01, Jose tomas R. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> wow, that was easy to fix. it''s ".id" cause i need just the product ID > thanks for your help and advicePlease quote previous message when replying, it makes it easier to follow the thread. I presume the fix was to use param[:id]. If all you need is the id itself why are you bothering to say Find the record with id params[:id] and then take the id of it? Why not just use params[:id] in the first place? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #962926:> On 21 November 2010 13:01, Jose tomas R. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> wow, that was easy to fix. it''s ".id" cause i need just the product ID >> thanks for your help and advice > > Please quote previous message when replying, it makes it easier to > follow the thread. I presume the fix was to use param[:id]. If all > you need is the id itself why are you bothering to say Find the record > with id params[:id] and then take the id of it? Why not just use > params[:id] in the first place? > > ColinI just notice that, so a :id => @product would be necessary to pass the id to the other controller, so the Product.find is useless -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 November 2010 14:44, Jose tomas R. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #962926: >> On 21 November 2010 13:01, Jose tomas R. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> wow, that was easy to fix. it''s ".id" cause i need just the product ID >>> thanks for your help and advice >> >> Please quote previous message when replying, it makes it easier to >> follow the thread. I presume the fix was to use param[:id]. If all >> you need is the id itself why are you bothering to say Find the record >> with id params[:id] and then take the id of it? Why not just use >> params[:id] in the first place? >> >> Colin > > I just notice that, so a :id => @product would be necessary to pass the > id to the other controller, so the Product.find is uselessSorry, that sentence makes no sense to me at all. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.