0
@@ -90,6 +90,13 @@ module ActionView
0
# link will be used in place of a referrer if none exists. If nil is passed as
0
# a name, the link itself will become the name.
0
+ # link_to(name, options = {}, html_options = nil)
0
+ # link_to(options = {}, html_options = nil) do
0
# * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
0
# prompt with the question specified. If the user accepts, the link is
0
@@ -147,6 +154,13 @@ module ActionView
0
# link_to "Profiles", :controller => "profiles"
0
# # => <a href="/profiles">Profiles</a>
0
+ # You can use a block as well if your link target is hard to fit into the name parameter. ERb example:
0
+ # <% link_to(@profile) do %>
0
+ # <strong><%= @profile.name %></strong> -- <span>Check it out!!</span>
0
+ # # => <a href="/profiles/1"><strong>David</strong> -- <span>Check it out!!</span></a>
0
# Classes and ids for CSS are easy to produce:
0
# link_to "Articles", articles_path, :id => "news", :class => "article"
0
@@ -189,27 +203,37 @@ module ActionView
0
# f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
0
# var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
0
# m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a>
0
- def link_to(name, options = {}, html_options = nil)
0
- @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
0
+ def link_to(*args, &block)
0
+ options = args.first || {}
0
+ html_options = args.second
0
+ concat(link_to(capture(&block), options, html_options))
0
+ options = args.second || {}
0
+ html_options = args.third
0
+ @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
0
+ html_options = html_options.stringify_keys
0
+ href = html_options['href']
0
+ convert_options_to_javascript!(html_options, url)
0
+ tag_options = tag_options(html_options)
0
- html_options = html_options.stringify_keys
0
- href = html_options['href']
0
- convert_options_to_javascript!(html_options, url)
0
- tag_options = tag_options(html_options)
0
+ href_attr = "href=\"#{url}\"" unless href
0
+ "<a #{href_attr}#{tag_options}>#{name || url}</a>"
0
- href_attr = "href=\"#{url}\"" unless href
0
- "<a #{href_attr}#{tag_options}>#{name || url}</a>"
0
# Generates a form containing a single button that submits to the URL created
Comments
Convenient :-)
Convenient :-)
cool, this helps readability in one of the spots where I think readability is most crucial. sugar that encourages descriptive linking, love it