How to use Ruby on Rails 5 + Ajax + jQuery to render a New Form on the Index View

Video is ready, Click Here to View ×


I’m learning to code in Ruby on Rails 5 with Ajax and a bit of jQuery. I had a hard time figuring out how to show the new item form on the index using Ajax, so that it doesn’t refresh the page or navigate to the new page view.

I got it working and thought I’d share how to do it.

In this video, you’ll see me modify link_to tag using remote: true, Ajax, and a bit of jQuery.

Upon clicking the link, it will instantly render the form partial on the index page, without refreshing or going to another page.

I hope this helped!

5 Comments on “How to use Ruby on Rails 5 + Ajax + jQuery to render a New Form on the Index View”

  1. My Project not work. the console in broesser respond: Uncaught ReferenceError: $ is not defined
    at <anonymous>:1:1
    at processResponse (rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:244)
    at rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:173
    at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:228)….Not Open form in index…..Whay? tanks….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.