Javascript 轨道6-可排序

Javascript 轨道6-可排序,javascript,ruby-on-rails,ruby,coffeescript,ruby-on-rails-6,Javascript,Ruby On Rails,Ruby,Coffeescript,Ruby On Rails 6,我对rails 6中的HTML可排序更新有问题 我想通过网页拖放图像,这很好,但当我想更新订单时,控制台日志中出现404 not found错误,find ID中也出现错误。 顺便说一句,我使用这个脚本进行HTML排序 控制器: class PortfoliosController < ApplicationController before_action :set_portfolio_item, only:[:edit , :show, :update , :destroy]

我对rails 6中的HTML可排序更新有问题 我想通过网页拖放图像,这很好,但当我想更新订单时,控制台日志中出现404 not found错误,find ID中也出现错误。 顺便说一句,我使用这个脚本进行HTML排序

控制器:

class PortfoliosController < ApplicationController
  before_action :set_portfolio_item, only:[:edit , :show, :update , :destroy]
  layout "portfolio"
  access all: [:show, :index , :angular], user: {except: [:destroy, :new , :create , :update , :edit , :sort]}, site_admin: :all
    def index
        # You can filter what you want to show in protfolio
        # Portfolio.where(subtitle: "Angular")
        # You can define it in models and call the method here
        # It must create on Portfolio.rb in models
        # You can create scope too on models and call
        @portfolio_items = Portfolio.by_position
    end
    def angular
      @angular_portfolio_items = Portfolio.angular
    end
    def sort
      params[:order].each do |key, value|
        Portfolio.find(value[:id]).update(position: value[:position])
      end
      head :ok
    end
    def new
      @portfolio_item = Portfolio.new
      3.times { @portfolio_item.technologies.build }
    end
    def create
      @portfolio_item = Portfolio.new(portfolio_params)
        respond_to do |format|
        if @portfolio_item.save
          format.html { redirect_to portfolios_path, notice: 'Portfolio was successfully created.' }
        else
          format.html { render :new }
        end
      end
      end
    def edit
    end
    def update
      respond_to do |format|
        if @portfolio_item.update(portfolio_params)
          format.html { redirect_to portfolios_path, notice: 'The record was successfully updated.' }
        else
          format.html { render :edit }
        end
      end
    end
    def show
    end
    def destroy
      # Perform the lookup
      # Destroy/delete the record
      @portfolio_item.destroy
      #Redirect
      respond_to do |format|
      format.html { redirect_to portfolios_url, notice: 'Portfolio was successfully deleted!.' }
    end
  end
    private
    def portfolio_params
      params.require(:portfolio)
    end
    def set_portfolio_item
      @portfolio_item = Portfolio.find(params[:id])
    end
    end
这是我的HTML排序咖啡脚本

ready = undefined
set_positions = undefined

set_positions = ->
  $('.card').each (i) ->
    $(this).attr 'data-pos', i + 1
    return
  return

ready = ->
  set_positions()
  $('.sortable').sortable()
  $('.sortable').sortable().bind 'sortupdate', (e, ui) ->
    updated_order = []
    set_positions()
    $('.card').each (i) ->
      updated_order.push
        id: $(this).data('id')
        position: i + 1
      return
    $.ajax
      type: 'PUT'
      url: '/portfolios/sort'
      data: order: updated_order
    return
  return

$(document).ready ready

谢谢你的帮助

“1”1“=>{“位置”>{“2”2“,,”2“=>{“位置”>{“3”3“,,”3“3”3“,,”3“=>{““““,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,[[[[[[[[[[[[[[[[[[=>“12”},“12”=>{“位置”=>“13”},“13”=>{“position”=>“14”},“14”=>{“position”=>“15”},“15”=>{“position”=>“16”},“16”=>{“position”=>“17”},“17”=>{“position”=>“18”}}完成了6967ms内找不到的404(ActiveRecord:2.1ms 12437)ActiveRecord::RecordNotFound(没有ID无法找到投资组合):app/controllers/portfolions\u controller.rb:19:in
block in sort'app/controllers/portfolions\u controller.rb:18:in
sort'of The position,如果我将find改为where then value[:id],我会在第一条评论中发送它有值并更新所有位置,但当我刷新页面时,顺序将恢复正常
ActiveRecord::RecordNotFound(没有ID无法找到公文包):app/controllers/portfolions\u controller.rb:18:in
block in sort`app/controllers/portfolions\u controller.rb:17:in
sort
ready = undefined
set_positions = undefined

set_positions = ->
  $('.card').each (i) ->
    $(this).attr 'data-pos', i + 1
    return
  return

ready = ->
  set_positions()
  $('.sortable').sortable()
  $('.sortable').sortable().bind 'sortupdate', (e, ui) ->
    updated_order = []
    set_positions()
    $('.card').each (i) ->
      updated_order.push
        id: $(this).data('id')
        position: i + 1
      return
    $.ajax
      type: 'PUT'
      url: '/portfolios/sort'
      data: order: updated_order
    return
  return

$(document).ready ready