Ruby on Rails Sunday, November 21, 2010

On 21 November 2010 01:39, Jose tomas R. <lists@ruby-forum.com> 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).id

Did 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 controller

Just 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@googlegroups.com.
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.

No comments:

Post a Comment