Aakash Uniyal Aakash Uniyal - 5 months ago 59
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]
params = params["body"]

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)

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download