Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. module ActionView
  2. module Helpers
  3. module UrlHelper
  4. def button_to(name, options = {}, html_options = {})
  5. html_options = html_options.stringify_keys
  6. convert_boolean_attributes!(html_options, %w( disabled ))
  7.  
  8. method_tag = ''
  9. if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
  10. method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
  11. end
  12.  
  13. form_method = method.to_s == 'get' ? 'get' : 'post'
  14.  
  15. request_token_tag = ''
  16. if form_method == 'post' && protect_against_forgery?
  17. request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
  18. end
  19.  
  20. if confirm = html_options.delete("confirm")
  21. html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
  22. end
  23.  
  24. url = options.is_a?(String) ? options : self.url_for(options)
  25. name ||= url
  26.  
  27. html_options.merge!("type" => "submit", "value" => name)
  28.  
  29. "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
  30. method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
  31. end
  32. end
  33. end
  34. end
Add Comment
Please, Sign In to add comment