passing proper arguments to application controller

Viewed 27

An application controller method requires two arguments generate_municipal_withins(municipal, radius) but in a separate controller action, calling this method is yielding

ArgumentError (wrong number of arguments (given 1, expected 2)):

from

@municipals.each do |municipal|
  generate_municipal_withins(municipal: municipal, radius: 70)

My assumption is that it is the former for if this is modified to generate_municipal_withins(municipal: municipal, 70) the same error is generated.

Thus it appears the member of the collection is not being passed as an argument. How should the syntax be fixed?

1 Answers

From the method definition, it tells the method is expecting to be called with two arguments, but you're using a single hash in:

generate_municipal_withins(municipal: municipal, radius: 70)

Doing method(municipal: municipal, radius: 70), is the same as method({municipal: municipal, radius: 70}), which is a single argument being a hash.

If your method is defined to use keyword arguments, then you could use the version shown in your question, but for that the method should be written as:

generate_municipal_withins(municipal:, radius:)
  ...
end

Try passing just municiapl and 70:

generate_municipal_withins(municipal, 70)
Related