I have followed the instructions on http://railscasts.com/episodes/147-sortable-lists for creating a sortable list.
The list drags and drops as it is supposed to, but the sort action is not being fired when the link is released. I have tested this by putting a render :text command into the sort.
No error's appear, it just doesn't fire off the action. I have tried other actions to test it and it doesn't go to them either.
Index:
<ul id="tasks">
<% @tasks.each do |task| %>
<%content_tag_for :li, task do %>
<span class ="handle"> [drag] </span>
<%= link_to task.name, task %>
<% end %>
<% end %>
</ul>
<%= sortable_element("tasks", :url => sort_tasks_path) %>
Controller:
开发者_运维知识库 def sort
#render :text => 'sorted'
params[:tasks].each_with_index do |id, index|
Task.update_all(['position=?', index+1], ['id=?', id])
end
#render :text => 'sorted'
render :nothing => true
end
route:
map.resources :tasks, :collection => {:sort => :post}
map.resources :tasks
forgot to sort the order of the tasks for display:
@tasks = Task.all(:order => "position")
精彩评论