Created
October 25, 2011 08:28
-
-
Save judofyr/1311840 to your computer and use it in GitHub Desktop.
Method override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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