Method: Padrino::Helpers::AssetTagHelpers#link_to

Defined in:
padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb

Creates a link element with given name, url and options.

Note that you can pass :if or :unless conditions, but if you provide :current as condition padrino return true/false if the request.path_info match the given url.

Examples:

link_to('click me', '/dashboard', :class => 'linky')
# Generates <a class="linky" href="/dashboard">click me</a>

link_to('click me', '/dashboard', :remote => true)
# Generates <a href="/dashboard" data-remote="true">click me</a>

link_to('click me', '/dashboard', :method => :delete)
# Generates <a href="/dashboard" data-method="delete" rel="nofollow">click me</a>

link_to('/dashboard', :class => 'blocky') { 'click me' }
# Generates <a class="blocky" href="/dashboard">click me</a>

Overloads:

  • #link_to(caption, url, options = {}) ⇒ String

    Parameters:

    • caption (String)

      The text caption.

    • url (String)

      The url href.

    • options (Hash) (defaults to: {})

      The html options.

  • #link_to(url, options = {}, &block) ⇒ String

    Parameters:

    • url (String)

      The url href.

    • options (Hash) (defaults to: {})

      The html options.

    • block (Proc)

      The link content.

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (String)

    Link tag html with specified options.

[View source] [View on GitHub]

84
85
86
87
88
89
90
91
# File 'padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb', line 84

def link_to(*args, &block)
  options = args.last.is_a?(Hash) ? args.pop : {}
  name = block_given? ? '' : args.shift
  href = args.first
  options = { :href => href ? escape_link(href) : '#' }.update(options)
  return name unless parse_conditions(href, options)
  block_given? ? (:a, options, &block) : (:a, name, options)
end