I’m trying to write a button_to statement that updates a boolean value in my activerecord database. Here’s what I tried:
<%= button_to "To Amazon", :controller => 'payments', :true => @payment.to_amazon, :method => :put %>
Bigger picture what I’m trying to do is have a button that updates a payment object and triggers a call to a private method for the gem remit to communicate with amazon payments. So:
1) How do I use button_to to update a boolean?
2) Is changing a boolean a good way to access a private method in the controller?
Well what you can do is use AJAX to make a callback to your controller to switch that boolean. In this case I would maybe just use a link or a checkbox instead, but in the end not a huge deal. If you want some code for an example on how to do this, let me know.
There was a similar question about specifying actions that I answered, and I used a link_to there like this:
So you can specify the action, but that only works with a link and not a button. But you could make some special action that did the update.
As for your secondary question, if I understand correctly, you want to set a boolean on the
@paymentobject then after call a private method? I assume you store the boolean in the database as well. So therefore your controller action could do something like this:Then in payment.rb (assuming your boolean column is just called “boolean_col” for lack of a better fake name):
I hope I’ve properly understood your question and have helped moved you towards an elegant solution.