-1

I'm sure this is something stupid but it's kicking my ass. I'm getting ArgumentError (wrong number of arguments (1 for 5)) but the header and the method call match as far as I can see.

Error Page (Photo) Image of error Error Page (Text, Same as photo)

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' 

This is my controller where the call is made.

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 

This is my helper where the method is implemented. I have other methods in the same helper that are called from the same controller without issue.

 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 

I can't see any problem but I've been trying to figure this out for a day. Note I have looked at the other questions about wrong number of arguments and they seem to be different issues.

Thanks for any help.

1 Answer 1

3

Your error says you are giving one argument to a method that expects five: storeMessage is defined as requiring five parameters, but when you call it on your controller, you are passing only one Hash:

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

Change your call like this:

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

And you'll see the error go away.

From your code, I think you are mixing Ruby syntax with other language's such as, maybe, PHP. I suggest you have a look at the Ruby and Ruby on Rails style guides. More precisely, you are defining all your variables in your controller as global (with $), which I'm quite sure that you don't need/want to do.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.