Ruby on Rails Saturday, February 4, 2017

Hi,

On Sat, Feb 4, 2017, at 12:52, Joe Guerra wrote:
>
>
> I have the following code in my show.html.erb file, it calls the right
> method (or path).
>
> I am unsure how to pass variables from my product show.html.etb to my
> actual method...
>
>
>
> <%= button_to 'Add to Cart', add_to_cart_path, method: :post %>
>
>
> I need to pass the product id, and possibly qty.
>

Add it as part of the url (something like `add_to_cart_path(product_id:
product.id, quantity: 1)`). If you need the quantity to be taken from an
input box then make a form instead of just a button.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1486197001.3407873.870045232.270AC06F%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment