Sortable Lists in Rails 5
In this article, you will learn how to get the railscast episode 147 on sortable lists to work with Rails 5.
//= require jquery-ui
content_tag_for was available in Rails 3 and 4. It has been removed from Rails 5. You can install
record_tag_helper to use that tag in Rails 5.
gem 'record_tag_helper', '~> 1.0'
Run bundle. Reload the faq page. You will get the error:
Add jquery-ui-rails gem to the Gemfile.
Run bundle. This still will not work. I installed
jquery-turbolinks gem to workaround turbolinks conflict with drag and drop functionality. This also failed. I had to remove turbolinks from Rails 5 to get it working.
- Remove turbolinks gem.
- Remove the turbolinks related code in application layout.
- Remove the turbo links require statement in application.js.
Now the drag and drop will work. You can download the code from Sortable Lists in Rails 5 without Turbolinks. You don't need
acts_as_list gem to fix the problem where a new faq has null value for the position. When a new faq is created, add a
before_create action that populates the position attribute to the existing highest position value + 1.