mr_muscle
mr_muscle

Reputation: 2900

Rails override passed request params

In my Rails 7 API only app I'm receiving the request with these params:

  def event_params
    params.permit(:event, :envelopeId, :action, :recipient)
  end

Inside the controller I need to set a guard based on event_params[:action] like below:

    class EventsController < BaseController
      def event_callback
        return unless event_params[:action] == 'envelopefinished'
        (...)
      end
    end

But it turns out the :action is default ActionController::Parameters parameter that represents the name of the action being performed (i.e., the method being called). Is it possible to get parameter event_params[:action] which was passed inside the JSON file without changing the JSON key name to something else?

Upvotes: 1

Views: 710

Answers (1)

max
max

Reputation: 102001

Its actually the router that overwrites params[:action] and params[:controller] but you can still access the raw parameters through the request object:

request.POST["action"]

This odd looking method (yeah its a method not a constant) is from Rack::Request::Helpers and gives the parsed parameters from the request body.

Upvotes: 4

Related Questions