instance method
link_to_function
Ruby on Rails 3.2.22.5
Since v2.2.3 Last seen in v4.0.13Signature
link_to_function(name, function, html_options={})
Returns a link whose onclick handler triggers the passed JavaScript.
The helper receives a name, JavaScript code, and an optional hash of HTML options. The name is used as the link text and the JavaScript code goes into the onclick attribute. If html_options has an :onclick, that one is put before function. Once all the JavaScript is set, the helper appends “; return false;”.
The href attribute of the tag is set to “#” unless html_options has one.
link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link" # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
Parameters
-
namereq -
functionreq -
html_optionsopt = {}
Source
# File actionpack/lib/action_view/helpers/javascript_helper.rb, line 102
def link_to_function(name, function, html_options={})
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
href = html_options[:href] || '#'
content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
end
Defined in actionpack/lib/action_view/helpers/javascript_helper.rb line 102
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::JavaScriptHelper