Module: Hikari::ViewHelpers::ActionView
- Defined in:
- lib/hikari/view_helpers/action_view.rb
Defined Under Namespace
Classes: HikariViewHelper
Instance Method Summary collapse
-
#link_to_sorted(*args, &block) ⇒ Object
Public: Create a sorted link.
Instance Method Details
#link_to_sorted(*args, &block) ⇒ Object
Public: Create a sorted link
args - link_to style arguments accepted
Examples
link_to_sorted "Title", :title
# => <a href="/posts?sort=title_asc" class="sortable">Title</a>
link_to_sorted :title do
<strong>Title</strong>
end
# => <a href="/posts?sort=title_asc" class="sortable"><strong>Title</strong></a>
link_to_sorted "Created At", {created_at: :desc}
# => <a href="/posts?sort=created_at_desc" class="sortable">Created At</a>
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hikari/view_helpers/action_view.rb', line 56 def link_to_sorted(*args, &block) if block_given? field = args[0] = args[1] || {} = args[2] || {} else block = proc { args[0].to_s } field = args[1] = args[2] || {} = args[3] || {} end sorter = HikariViewHelper.new(field, ((request.try(:get?) && !params.nil?) ? params.dup : {})) [:class] = [[:class], sorter.css(field)].join(' ').strip link_to(url_for(sorter.params), , , &block) end |