Method: ActionView::Helpers::JavaScriptHelper#button_to_function
- Defined in:
- lib/action_view/helpers/javascript_helper.rb
#button_to_function(name, *args, &block) ⇒ Object
Returns a button that’ll trigger a JavaScript function using the onclick handler.
The function argument can be omitted in favor of an update_page block, which evaluates to a string when the template is rendered (instead of making an Ajax request first).
Examples:
"Greeting", "alert('Hello world!')"
"Delete", "if (confirm('Really?')) do_delete()"
"Details" do |page|
page[:details].visual_effect :toggle_slide
end
"Details", :class => "details_button" do |page|
page[:details].visual_effect :toggle_slide
end
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/action_view/helpers/javascript_helper.rb', line 113 def (name, *args, &block) = args.last.is_a?(Hash) ? args.pop : {} function = args[0] || '' .symbolize_keys! function = update_page(&block) if block_given? tag(:input, .merge({ :type => "button", :value => name, :onclick => ([:onclick] ? "#{[:onclick]}; " : "") + "#{function};" })) end |