I followed several tutorial to make this work, but I can't get draggable items. Here's what i did:
added gem 'acts_as_list'
in my GemFile and did a bundle install
added <%= javascript_include_tag :defaults %>
to my application.html.erb
added an :integer
column named position to my facilities;
added acts_as_list
in my facility model;
added the sort method in my facility model:
def sort
@facilities = Facility.all
@facilities.each do |f|
f.position = params['f'].index(f.id.to_s) + 1
f.save
end
end
added this in my view:
<ul id="facilities">
<% for facility in Facility.all %>
<% content_tag_for :li, facility do %>
<span class="handle">[drag]</span>
<%= link_to h(facility.name), facility %>
<% end %>
<% end %>
</ul>
<%= sortable_element("facilities", :url => sort_facilities_path, :handle => "handle") %>
added this to the routes:
resources :facilities do
collection do
post :sort
end
end
But in the end i have only a normal list, not draggable! What am i missing?
Thanks!
As far as I remember does acts_as_list
only deal with lists in Rails' models which means the server side of things. In order to make a list element draggable you'll have to include a client side library or plugin such as jQuery UI. The gem itself doesn't (or at least didn't use to) include the functionality you're describing.
This library or solution will then