Skip to content

Ajaxifying a set of links

Ronald Chan edited this page Mar 13, 2012 · 1 revision

The ajax_links helper method can automatically ajaxify all the links created within this container.

When it is used, all normal links inside are all regarded as AJAX links. This is useful when there are a number of links located together, for example in a menu. This feature is quite important because it can simplify the code in the views.

For individual links, it is better to use the ajax_link_to helper.

Because ajax_links is only for convenience, avoiding a large number of ajax_link_to calls, it only supports plain GET requests. Supporting other types of requests as well would be problematic, and using the ajax_link_to helper would be more appropriate.

The other reason ajax_links is used, is to make using gems such as will_paginate easy, since the links can be easily wrapped using this helper method.

It can be used with as shown below:

<%= ajax_links :section_id => "page" do %>
  <%= will_paginate @objects %>
<% end %>