Suppose I have an object @transaction that gets shown /transactions/id
def show
@transaction = Transaction.find(params[:id]);
end
In show.html.erb, I want to have a button that when pressed changes one of the attributes of Transaction. How do I do that?
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 with the question. The button code above generates this html:
<input id="transaction_submit" name="commit" type="submit" value="pay" />
When I click on the button, the “update” method in the controller is called. How do I pass the value from a button to a specific action in the update method? For example, suppose button1changes the transaction.name to “lalala”. How do I do this?
def update
// if button1 is pressed, change transaction.name to lalala
// if button2 is pressed, change transaction.amount to bobobo
end
Use a different form for each button: