How to add a custom commit to from.submit in rails

To add a custom commit message to the form submit button in Rails, you can pass the commit option to the submit method, like this:

<%= form.submit "Create User", name: "commit_create_user" %>

In the controller, you can then check for the presence of this commit parameter to determine which action to take, like this:

def create
if params[:commit] == "commit_create_user"
# handle create user action
elsif params[:commit] == "commit_update_user"
# handle update user action
end
end

This code checks the value of the commit parameter and performs the appropriate action based on its value.

Leave a Comment

Your email address will not be published. Required fields are marked *