Skip to content

Instantly share code, notes, and snippets.

@the-undefined
Last active January 20, 2016 15:28
Show Gist options
  • Save the-undefined/b189ef5b8c14a1a3782f to your computer and use it in GitHub Desktop.
Save the-undefined/b189ef5b8c14a1a3782f to your computer and use it in GitHub Desktop.
Presenter that yield to the view for route information
class Presenter
include SortableColumns
def sortable_column_heading(text:, attr:, &block)
label = sort_link_text(text, attr)
link_params = sort_link_params(attr)
block.call(label, link_params)
end
private
attr_reader :view_context
def initialize(view_context: view_context)
@view_context = view_context
end
end
<table>
<thead>
<tr>
<th>
<% @presenter.sortable_column_heading(
text: 'First Name',
attr: 'first_name') do |label, sort_params| %>
<%= link_to label, sort_params %>
<% end %>
</th>
<th>
<% @presenter.sortable_column_heading(
text: 'Email',
attr: 'email') do |label, sort_params| %>
<%= link_to label, sort_params %>
<% end %>
</th>
</tr>
</thead>
<tbody>
...
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment