Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created October 25, 2011 08:28
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 judofyr/1311840 to your computer and use it in GitHub Desktop.
Save judofyr/1311840 to your computer and use it in GitHub Desktop.
Method override
require 'camping'
Camping.goes :Ex
module Ex
use Rack::MethodOverride
end
module Ex::Helpers
SUPPORTED = %w[get post]
def form(options)
meth = options[:method]
override = !SUPPORTED.include?(meth)
options[:method] = 'post' if override
super(options) do
input type: 'hidden', name: '_method', value: meth if override
yield
end
end
end
module Ex::Controllers
class Index
def get() render :index end
def delete() 'DELETE!' end
end
end
module Ex::Views
def index
form method: 'delete', action: R(Index) do
input type: 'submit', value: 'Delete'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment