I'm trying to run a method in one of my controllers using a button_to
command. How is this accomplished?
So far, I've got <%= button_to "Add to Cart", action: "add_to_cart" %> in
my products page
I defined a add_to_cart in my product controller, and created a route for
it.
Am I on the right track? Will it execute code in that method in that
controller?
Try it and see, that would be a lot quicker than asking here. If it doesn't
then look in log/development.log and/or the server terminal window to get a
clue as to why not. When setting the route don't forget that button_to
will use POST.
OK, maybe I just need to see an example of how to call a method from a button-to button.
No you need to show us what you have done and tell us what is not working. Which bit is failing? Is it getting to your controller action? Is it failing running the action? Is it not rendering the next view correctly? Or what. Show us the specific bit of code that is not working.