Ruby 在 rails 上。 ArgumentError(参数数量错误(1 对 5))。 Header 应该匹配

Ruby on rails. ArgumentError (wrong number of arguments (1 for 5)). Header should match

我确定这是愚蠢的事情,但它正在踢我的屁股。我收到 ArgumentError(参数数量错误(1 对 5)),但据我所知 header 和方法调用匹配。

错误页面(照片) 错误页面(文字,与照片相同)

ArgumentError in MessageServiceController#put
wrong number of arguments (1 for 5)
Extracted source (around line #14):


end
def storeMessage(from_host, to_host, service, message, arguments)
$fh = from_host
$th = to_host

Rails.root: -------------------------
Application Trace | Framework Trace | Full Trace

app/helpers/message_service_helper.rb:14:in `storeMessage'
app/controllers/message_service_controller.rb:20:in `put'

Request

Parameters:

{"message"=>"9,
9,
9,
9,
9,
9"}

Started GET "/message_service/put?message=9,9,9,9,9,9" for 127.0.0.1 at 2015-03-01 14:04:53 +0000
Processing by MessageServiceController#put as HTML
  Parameters: {"message"=>"9,9,9,9,9,9"}

Completed 500 Internal Server Error in 1ms

ArgumentError (wrong number of arguments (1 for 5)):
  app/helpers/message_service_helper.rb:14:in `storeMessage'
  app/controllers/message_service_controller.rb:22:in `put'

这是我的控制器,调用的地方。

class MessageServiceController < ApplicationController
  include MessageServiceHelper

  def put

    $messageSplit = params[:message].split(",")

    $to_host = $messageSplit[0]
    $from_host = $messageSplit[1]
    $service = $messageSplit[2]
    $message = $messageSplit[3]
    $arguments = $messageSplit[4]

    storeMessage(from_host:$from_host, to_host:$to_host, service:$service, message:$message, arguments:$arguments)

    render :layout => false
  end

这是我的助手实现方法的地方。我在同一个助手中有其他方法,可以毫无问题地从同一个控制器调用。

  def storeMessage(from_host, to_host, service, message, arguments)

    Message.create(from_host:from_host, to_host:to_host, service:service, message:message, arguments:arguments)

  end

我看不出有什么问题,但我已经尝试解决了一天。请注意,我已经查看了有关错误数量参数的其他问题,它们似乎是不同的问题。

感谢您的帮助。

你的错误说你给一个需要五个参数的方法提供了一个参数:storeMessage 被定义为需要五个参数,但是当你在你的控制器上调用它时,你只传递了 一个哈希

storeMessage(from_host:$from_host, to_host:$to_host, service:$service, message:$message, arguments:$arguments)

像这样改变你的电话:

storeMessage($from_host, $to_host, $service, $message, $arguments)

你会看到错误消失了。

根据您的代码,我认为您将 Ruby 语法与其他语言的语法混合在一起,例如 PHP。我建议你看看 Ruby and Ruby on Rails style guides. More precisely, you are defining all your variables in your controller as global(和 $),我很确定你不会 need/want 去做。