-1

I have the following code in my routes.rb file -

post "/webhooks/process/:webhook_source", controller: :webhooks, action: :process

What is expected is that it would pass the webhook_source as a param in the action.

Here is the action -

  def process(webhook_source)
    puts "========="
    puts webhook_source
    puts "========="
    case params[:webhook_source]
    when 'razorpay'
      process_razorpay(params)
    end
    head :ok
  end

If I don't have the argument webhook_source, I get the error -

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

Here is the full stack track for reference as well.

And the puts of webhook_source just returns process.

I'm unsure of how to get rid of the argument which I think is redundant.

Michael Victor
  • 861
  • 2
  • 18
  • 42

1 Answers1

0

This is because of the syntax error as the methods in the class that inherit ActionController can't have method params of thier own. Your process method should be

def process 
    puts "========="
    puts params[:webhook_source]
    puts "========="
    case params[:webhook_source]
    when 'razorpay'
      process_razorpay(params)
    end
    head :ok
 end

Update:

The problem lies in the name of the method. process is a keyword used by AbstractController#Base. Defining the method with different name that is not a keyword would solve the trouble.

sureshprasanna70
  • 1,043
  • 1
  • 10
  • 27
  • I get the error only when I have the code without the params.. I have to include the params for it to go away.. – Michael Victor Nov 11 '19 at 06:52
  • 1
    May be you should use a different name to the method. `process` could be a keyword in `rails` – sureshprasanna70 Nov 11 '19 at 08:19
  • @sureshprasanna70 good catch. You are correct `process` is method defined by rails https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/base.rb#L127 and it got overridden by action method in the controller. – edariedl Nov 11 '19 at 10:38