ruby on rails - How to edit output from Ransack's "sort_link" method? -
ruby on rails - How to edit output from Ransack's "sort_link" method? -
as total noob ruby on rails have, hope, simple question.
i'm using ransack gem powerfulness site's search bar , there bunch of great methods. 1 of them sort_link method makes table of results sortable clicking on element.
the problem when sorts, injects ▼
(or ▲
) after column header name.
all i'm trying edit output <span>▲</span>
or <span>▼</span>
instead. after looking everywhere , asking question in #rubyonrails irc can't seem find way customize output.
as stop-gap, i've written javascript straight manipulate dom feels dirty approach, in custom site!
any help here awesome.
thanks!
here in ransack gem source on github
# lib/ransack/constants.rb:5-6 module ransack module constants asc = 'asc'.freeze desc = 'desc'.freeze asc_arrow = '▲'.freeze # <- ascending arrow desc_arrow = '▼'.freeze # <- descending arrow # ..snipped..
to swap arrow directions, re-create file application here: /lib/ransack/constants.rb
, swap 2 html entities (or swap asc_arrow
, desc_arrow
).
edit
to add together span tag , remove non-breaking space, modify helper method handles both.
in this file take helper method
# lib/ransack/helpers/form_helper.rb:143 def link_name(label_text, dir) [erb::util.h(label_text), order_indicator_for(dir)] .compact .join(ransack::constants::non_breaking_space) .html_safe end
and modify to:
wrap order indicator arrow inspan
tag remove nbsp;
copy raw file application (to /lib/ransack/helpers/form_helper.rb) , alter method like:
# lib/ransack/helpers/form_helper.rb:143 def link_name(label_text, dir) [erb::util.h(label_text), content_tag(:span, order_indicator_for(dir))] .compact .html_safe end
ruby-on-rails ruby ransack
Comments
Post a Comment