Created
September 14, 2012 10:43
-
-
Save koorchik/3721253 to your computer and use it in GitHub Desktop.
Override "form_for"
This file contains hidden or 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
| # Replace "form_for" helper | |
| my $original_form_for = delete $app->renderer->helpers->{form_for}; | |
| croak qq{Cannot find helper "form_for". Please, load plugin "TagHelpers" before} | |
| unless $original_form_for; | |
| $app->helper( form_for => sub { | |
| my $c = shift; | |
| if ( defined $_[-1] && ref( $_[-1] ) eq 'CODE' ) { | |
| my $cb = $_[-1]; | |
| $_[-1] = sub { $app->hidden_field( '_method' => 'PUT' ) . $cb->() }; | |
| } | |
| return $app->$original_form_for(@_); | |
| } ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment