Prepare for PUT/DELETE support in forms and controllers
This commit is contained in:
parent
69bf1bd735
commit
45da051bf0
20
stoptime.rb
20
stoptime.rb
|
@ -62,6 +62,9 @@ module StopTime
|
||||||
Models::Config.instance.reload
|
Models::Config.instance.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add support for PUT and DELETE.
|
||||||
|
use Rack::MethodOverride
|
||||||
|
|
||||||
# Enable SASS CSS generation from templates/sass.
|
# Enable SASS CSS generation from templates/sass.
|
||||||
use Sass::Plugin::Rack
|
use Sass::Plugin::Rack
|
||||||
|
|
||||||
|
@ -72,6 +75,23 @@ module StopTime
|
||||||
|
|
||||||
end
|
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
|
# = The Stop… Camping Time! models
|
||||||
module StopTime::Models
|
module StopTime::Models
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue