Link via image map

I’m looking to create a small icon to use in table headings, that users
can use to sort by that table heading. Click on the top half and sort
ascending, and click on the bottom half to sort desc.

Is there a way to neatly generate an image map via Rails. I want to
create output HTML something like this:

I can build my own helper method to do this, but wondered if there was
already a way to do it.

As I’ve had no reply, I guess the answer is no - there isn’t an existing
method. I’ve thrown these helper methods together which does the job for

def image_map_for_sort_link(name, field)
params_for_link = params.clone
params_for_link.delete_if{|key,value| key == ‘order’ or key ==
output =
output << [’’].join
output << image_map_area(“0,0,20,18”, url_for(:sort_by => field,
:params => params_for_link, :order => ‘asc’))
output << image_map_area(“20,0,40,18”, url_for(:sort_by => field,
:params => params_for_link, :order => ‘desc’))
output << ‘’
return output.join("\n")

def sort_image(field="")
map_name = “sort_#{field}”
@image_maps = unless @image_maps
@image_maps << image_map_for_sort_link(map_name, field)
image_tag(‘sort.png’, :usemap => “##{map_name}”, :class =>

def image_map_area(coords, url)

The result is that adding <%= sort_image(‘field_name’) -%> to a view
adds a clickable sort image, as long as I also have <%= @image_maps %>
somewhere on the page. I also have to handle params[:sort_by] and
params[:order] in the controller to handle the sorting.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs