Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created April 24, 2014 23:26
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 pjb3/11272968 to your computer and use it in GitHub Desktop.
Save pjb3/11272968 to your computer and use it in GitHub Desktop.
How link to works
<%= link_to "Text", "/link" %>
<a href="/link">Text</a>
<%= link_to "Text", product_path(product) %>
<a href="/products/1">Text</a>
<% link_to "<span class='icon'>Text</span>", '/link' %>
<a href="/products/1">
<span class='icon'>Text</span>
</a>
<%= link_to '/link' do %>
<span class='icon'>Text</span>
<% end %>
<a href="/products/1">
<span class='icon'>Text</span>
</a>
<%
def link_to(product)
if product.is_a?(ActiveRecord::Base)
"/products/1"
product_path(product)
"product_path"
"#{product.class.name.underscore}_path"
else
product
end
end
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment