Fraser Price Fraser Price - 3 months ago 11
Ruby Question

Params not being saved in rails

Disclaimer: I am very new to Ruby + rails. I'm not sure if this is a bug, but my

params
variable always seems to be null. I am working on a large and unfamiliar codebase so I'm not sure if it's something else interfering or my own code; any suggestions would be welcome however.

In my routes file I have
match '/proxy_request/:number/:ref' => 'proxies#show', via: :get
- I was under the impression that this would store
:number
and
:ref
variables in
params
. However when my
proxies#show
function runs (below), params is an empty hash.

In case it probably is something else interfering with
params
, is there another way to pass
:number
and
:ref
to
proxies#show
?

class ProxiesController < ApplicationController

include Service

skip_before_action :restrict_access!

def show
binding.pry #params is null here
data = { date: Adapter.staging_date.get(params[:number], params[:ref])}
render json: data, content_type: "application/javascript", callback: @_request.env["QUERY_STRING"].match(/jQuery\d*_\d*/)
end

end

Answer

I removed the include Service and all seems to be ok now