Suavocado
Suavocado

Reputation: 969

Activate Rails link_to ajax , call with jquery

I have a rails view with these remote link_to's

<%= link_to 'next', next_page_path, remote:true %>
<%= link_to 'previous', previous_page_path, remote:true%>

I want to make it possible to activate these with the left and right arrow buttons on the keyboard?. Is there a way to do this without using JQuery "click" function?

Upvotes: 3

Views: 564

Answers (1)

ifma
ifma

Reputation: 3818

Edit: Misread your question, you can bind the link_to to a specific key like so:

<%= link_to 'previous', previous_page_path, :html_options => {:accesskey => "LEFT ARROW"} %>

Old answer (icons):

What type of icons are you wanting to use? You can make use of the .html_safe helper method. Here's an example with a FontAwesome icon:

<%= link_to '<i class="fa fa-heart-o"></i>'.html_safe,
    {controller: "users", action: "save_user", user: @user} %>

And one without using the helper, using your example:

<%= link_to next_page_path do %>
    <i class="fa fa-arrow"></i>
<% end %>

In this way if you click the icon, you are redirected to the appropriate view or controller/action.

Upvotes: 2

Related Questions