link_to is an example of a Rails function for html generation and is typically used to add site-wide navigation. For example,
<%= link_to('Home', { :action = 'index'}) %> |
<%= link_to('About Us', { :action ='about'}) %>
You may be interested to note that curly braces are optional in hashes where they are the final argument to a function as follows :-
<%= link_to('About Us',:action ='about') %>
How does one not link to a page that is currently displayed ?
<%= link_to_unless_current('Home', { :action = 'index'}) %> |
<%= link_to_unless_current('About Us', { :action ='about'}) %>
Are there other related link_to functions ?
Rails adheres to a naming convention whereby a group of related functions have related names, usually of the form original_function_name and original_function_name_with_modification
Let's check to the Rails API via the Rails API Tab in Aptana Radrails or at http://api.rubyonrails.org and this is what you should find
- link_to
- link_to_if
- link_to_remote
- link_to_unless
- link_to_unless_current
<%= link_to image_tag("about.gif", :border=>0), :action => 'about' %>
1 comment:
Should be :action => 'index', not :action = 'index'
Post a Comment