【问题标题】:rails sortable list not updatingrails可排序列表未更新
【发布时间】:2010-08-26 23:10:05
【问题描述】:

我已按照 http://railscasts.com/episodes/147-sortable-lists 上的说明创建可排序列表。

列表按预期拖放,但释放链接时不会触发排序操作。我已经通过将 render :text 命令放入排序中进行了测试。

没有错误出现,只是没有触发动作。我已经尝试了其他操作来测试它,但它也没有发生在他们身上。

索引:

<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) %>

控制器:

 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

路线:

  map.resources :tasks, :collection => {:sort => :post}

  map.resources :tasks

【问题讨论】:

    标签: ruby-on-rails list action jquery-ui-sortable


    【解决方案1】:

    忘记排序显示的任务顺序:

    @tasks = Task.all(:order => "position")
    

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 2017-12-08
      • 2012-06-07
      相关资源
      最近更新 更多