Skip to content

Instantly share code, notes, and snippets.

@laktek
Created March 23, 2009 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laktek/83810 to your computer and use it in GitHub Desktop.
Save laktek/83810 to your computer and use it in GitHub Desktop.
#without :ujs option
link_to_function("Greeting", "alert('Hello world!')")
# <a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
#with :ujs and :id option
link_to_function("Greeting", "alert('Hello world!')", :id => "greeting_link", :ujs => true)
# <a href="#" id="greeting_link">Greeting</a>
# <script type="text/javascript">
# //assuming users JS framework of choice is jQuery
# $(\"#greeting_link\").click( function(){ alert('Hello world!'); return false } );
# </script>
#with :ujs and :class option
link_to_function("Greeting", "alert('Hello world!')", :class => "greeting_link", :ujs => true)
link_to("Greeting", "#", :class => "greeting_link")
# <a href="#" class="greeting_link">Greeting</a>
# <a href="#" class="greeting_link">Greeting</a>
# <script type="text/javascript">
# //assuming users JS framework of choice is jQuery
# $(\".greeting_link\").click( function(){ alert('Hello world!'); return false } );
# </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment