Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Form with multiple button in rails
/ Form excerpt
= f.button t(".save"), class: "btn"
= f.button t(".publish"), class: "btn", name: "publish"
= f.button t(".test"), class: "btn", name: "test"
class MultibuttonFormConstraint
def initialize(button_name)
@button_name = button_name
end
def matches?(request)
request.params.key? @button_name
end
end
# Add new routes with appropriate constrains
resources :subscriptions do
patch '' => "subscriptions#publish", on: :member, constraints: MultibuttonFormConstraint.new(:publish)
patch '' => "subscriptions#test", on: :member, constraints: MultibuttonFormConstraint.new(:test)
end
class SubscriptionController < ApplicationController
# CRUD
def update
# process REST update
end
def publish
# process publish action
end
def test
# process test action
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.