Skip to content

Instantly share code, notes, and snippets.

@harshamv
Forked from scarfacedeb/1.form.html.haml
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshamv/ebf41db152ca8fd1e3a8 to your computer and use it in GitHub Desktop.
Save harshamv/ebf41db152ca8fd1e3a8 to your computer and use it in GitHub Desktop.
/ 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