Suppose I have an @transaction object that displays / transaction / id
def show @transaction = Transaction.find(params[:id]); end
In show.html.erb, I want to have a button that, when clicked, changes one of the attributes of a transaction. How to do it?
In show.html.erb, I have
<%= form_for @transaction do |t| %> <%= t.label :id %> : <%= @transaction.id %><br /> <%= t.submit "pay" %> <% end %>
EDIT: I think I may have misled the question. The button code above generates this html:
<input id="transaction_submit" name="commit" type="submit" value="pay" />
When I click the button, the update method in the controller is called. How to transfer a value from a button to a specific action in the update method? For example, suppose button1
changes the name of a transaction to "lalala". How to do it?
def update // if button1 is pressed, change transaction.name to lalala // if button2 is pressed, change transaction.amount to bobobo end
source share