Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails jQuery sortable无法保存_Javascript_Ruby On Rails_Jquery Ui_Acts As List - Fatal编程技术网

Javascript Rails jQuery sortable无法保存

Javascript Rails jQuery sortable无法保存,javascript,ruby-on-rails,jquery-ui,acts-as-list,Javascript,Ruby On Rails,Jquery Ui,Acts As List,我正在尝试使用jQuery使我的表可排序拖放,我遇到的问题是保存新的排序表,然后将其发布给其他用户或在刷新浏览器时发布 我正在使用: gem“作为列表” 轨道3.2.17 ruby 1.9.3p484 有更好的方法吗 我的控制器上的排序和显示方法 def排序 @剧集=当前用户。剧集_for@show.each一集| eposition.position=params['eposition'].indexepisode.id.to_+1 保存 终止 render:nothing=>true 结束

我正在尝试使用jQuery使我的表可排序拖放,我遇到的问题是保存新的排序表,然后将其发布给其他用户或在刷新浏览器时发布

我正在使用:

gem“作为列表” 轨道3.2.17 ruby 1.9.3p484

有更好的方法吗

我的控制器上的排序和显示方法

def排序 @剧集=当前用户。剧集_for@show.each一集| eposition.position=params['eposition'].indexepisode.id.to_+1 保存 终止 render:nothing=>true 结束

我的Javascript

<script>
$(window).load(function() {
    $("#sortthis").sortable({
      axis: 'y',
      placeholder: 'ui-state-highlight',
      cursor: 'move',
      dropOnempty: false,
      scroll: true,
      opacity: 0.4,

      update: function(event, ui){
        var itm_arr = $("#sortthis").sortable('toArray');
        var pobj = {episodes: itm_arr};
        $.post("/episodes/sort", pobj);
      }

    });
});
 </script>
我要在视图中排序的表:

<tbody id='eps'>
<tr>
  <th>Title</th>
  <th>#</th>
  <th>Season</th>
  <th>Download?</th>
  <th>Shared?</th>
  <th>Length</th>
  <th>Status</th>
        <th></th>
</tr>
<% for episode in @episodes %>
  <tr>
    <td id="eps_<%= episode.id %>", width="20%"><%=h episode.title %></td>
    <td id="eps_<%= episode.id %>"><%=h episode.number %></td>
    <td id="eps_<%= episode.id %>"><%=h episode.season %></td>
    <td id="eps_<%= episode.id %>"><%=h episode.is_downloadable %></td>
    <td id="eps_<%= episode.id %>"><%=h episode.shared_with_dev %></td>
    <td id="eps_<%= episode.id %>"><%=h episode.length %></td>
    <td>
      <% if episode.video %>
        <%= link_to 'Replace Video', new_show_episode_video_path(episode.show, episode) %>
      <% else %>
        <%= link_to 'Upload Video', new_show_episode_video_path(episode.show, episode) %>
      <% end %>
    </td>
        <td>
        <%= link_to "View", [episode.show, episode] %> &nbsp;
    <%= link_to "Edit", edit_show_episode_path(episode.show, episode) if permitted_to? :update, episode %> &nbsp;
    <%= link_to "Delete", show_episode_path(episode.show, episode), :confirm => 'Are you sure?', :method => :delete if permitted_to? :delete, episode %>
    </td>
  </tr>
<% end %>


任何帮助都将不胜感激

我弄明白了,做了以下更改:

观点:

<tr id="<%= episode.id %>">
最后在我的模型中添加了以下内容:

  acts_as_list
  default_scope order('position')
如果有人有类似的问题,请告诉我

def sort
  Episode.all.each do |e|
    if position = params[:episodes].index(e.id.to_s)
      e.update_attribute(:position, position + 1) unless e.position == position + 1
    end
  end
  render :nothing => true, :status => 200
end
  acts_as_list
  default_scope order('position')