Method: ActionView::Helpers::JavaScriptHelper#link_to_function

Defined in:
lib/action_view/helpers/javascript_helper.rb

Returns a link that’ll trigger a javascript function using the onclick handler and return false after the fact.

Examples:

link_to_function "Greeting", "alert('Hello world!')"
link_to_function(image_tag("delete"), "if confirm('Really?'){ do_delete(); }")


42
43
44
45
46
47
# File 'lib/action_view/helpers/javascript_helper.rb', line 42

def link_to_function(name, function, html_options = {})
  (
    "a", name, 
    {:href => "#", :onclick => "#{function}; return false;"}.merge(html_options.symbolize_keys)
  )
end