Aakash Uniyal Aakash Uniyal - 23 days ago 10
Ruby Question

RoR : Params object modified in 1 controller does not propogates to the chained controllers

I am modifying params object in my application_controller which handles all the routes coming with root . I have multiple controllers that chain behind the application_controller .

I modified the params object in the application_controller but i get the original params object in the subsequent controllers .

Note: After modification in the application controller i printed out the params ,it got modified there. But when i printed out the same in the subsequent controllers it was back in the original state .

Application Controller (Application Controller is in a core Engine which is the first controller that gets hit by the request)

before_action :handle_params
def handle_params
param = nil
#Identify method from request object
method = request.method #Come from request.method
if method == "GET"
param = JSON.parse(URI.unescape(params["body"]))
params[:header] = param[:header]
params[:data] = param[:data]
else
params = params["body"]
end
end


In my Common Engine i have this controller LoaderController that gets called after the application_controller.

require_dependency "core/application_controller"

module Common
class API::LoaderController < Core::ApplicationController
def fetch
pp params
responder FetchLoader.call(@context,params)
end
end
end


Rails newbie here , do let me know if any more information is needed .

Answer Source

Have you tried this?

self.params = self.params["body"]

It worked for me.