【问题标题】:ArgumentError (wrong number of arguments (given 1, expected 2))ArgumentError(错误数量的参数(给定 1,预期 2))
【发布时间】:2021-07-18 16:40:52
【问题描述】:

不确定我在这里忽略了什么:

执行 ActionCable 的行中的 ArgumentError(参数数量错误(给定 1,预期为 2))

控制器:

respond_to do |format|
  if @message.save  
    ActionCable.server.broadcast "room_channel_#{@message.room_id}", message: "hello"
    format.json { render :show, status: :created, location: @message }
  else
    format.html { render :new, status: :unprocessable_entity }
    format.json { render json: @message.errors, status: :unprocessable_entity }
  end
end

导轨 6.1.3.2 红宝石 3​​.0.1p64

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    也许它期待一个实际的参数,而不是第二个关键字 arg? The code you wrote passes (with a warning) on Ruby 2.7 but no longer works on Ruby 3.

    ActionCable.server.broadcast "room_channel_#{@message.room_id}", { message: "hello" }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    相关资源
    最近更新 更多