Joe_Guerra
(Joe Guerra)
February 4, 2017, 3:52am
1
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.
Thanks,
Joe
Greg_Navis
(Greg Navis)
February 4, 2017, 8:13am
2
button_to generates a form with a button. I’m not sure there’s a way to add custom hidden fields to the form. One way around the problem would be to create the form manually, add the hidden input (with product ID), a number input with quantity and the submit button.
Would this work for you?
hassan
(Hassan Schroeder)
February 4, 2017, 3:13pm
4
One way around the "problem" would be to read the documentation
for that method, which includes under "options"
:params - Hash of parameters to be rendered as hidden fields within the form.
FWIW,
You can put the parameters as an argument to a path like so:
=link_to “Add Special”, add_special_path(work_day: @date ), class: 'uk-button buffer-left-twice’ which will make a url like
http://xxx.com/time/add_special?work_day=2017-02-04
Or if you have a model that is already in the button, you put parameters after it like:
%= link_to ‘Confirm my account’, confirmation_url(@resource , :confirmation_token => @token )
This is from Devise on their default views
Greg_Navis
(Greg Navis)
February 7, 2017, 9:25am
6
D’oh! Thanks for correcting me, Hassan. I consulted the docs but somehow completely missed that.