In searching for a solution to a javascript problem, I saw multiple comments about link_to_function
being deprecated in Rails 3. However, I\'ve been able to co
The link_to_function
helper has been deprecated again in 3.2.4.
The method itself is quite simply and good in some use cases when you need to call specific javascript function etc. You can easily add your own helper to achieve the same functionality. The following code was copied from Jeremy in https://github.com/rails/rails/pull/5922#issuecomment-5770442
# /app/helpers/link_to_function_helper.rb
module LinkToFunctionHelper
def link_to_function(name, *args, &block)
html_options = args.extract_options!.symbolize_keys
function = block_given? ? update_page(&block) : args[0] || ''
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
end