Ads by ProfitSence

Performing AJAX Calls in Rails Code Example

Last Updated on Wednesday 5th Oct 2022

In Rails, there are so many view helper methods written in Ruby to generate HTML.

  • It is also possible to add AJAX to the generated HTML elements using the AJAX helpers provided in Rails.
  • This is achieved with the Rails helper remote: true.

Making the ajax request with remote: true helper in the View

					<%= link_to admin_message_path(, method: 'put', remote: true do %>
  <span id=<%= "button-text-#{}" %>><%= display_text(msg) %></span>
<% end %>

  • The Rails helper remote: true can be added to any other Rails view helper that generates a web request.
  • It will stop the default action like preventDefault().