From 45da051bf04682ebb1ad5a550113ed0f53e920b2 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 20 Jan 2012 00:35:44 +0100 Subject: [PATCH] Prepare for PUT/DELETE support in forms and controllers --- stoptime.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 6e4a920..f0da048 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -62,6 +62,9 @@ module StopTime Models::Config.instance.reload end + # Add support for PUT and DELETE. + use Rack::MethodOverride + # Enable SASS CSS generation from templates/sass. use Sass::Plugin::Rack @@ -72,6 +75,23 @@ module StopTime end +# = The Stop… Camping Time! helpers +module StopTime::Helpers + SUPPORTED = %w[get post] + + # Adds a method override for (usually) unsupported methods by browsers + # (i.e. PUT and DELETE) by injecting a hidden field to forms. + 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 + # = The Stop… Camping Time! models module StopTime::Models