samedi 19 septembre 2015

Accessing Custom URL Params in Controller Action

In my rails 4 application I have a url that is passing through an external service object ID (DocuSign object ID). I'm trying to access that ID that is in the URL's params in my controller to generate a subsequent URL.

My route:

resources :pledge, only: [:show, :update]
  resources :documents, only: [:show], param: :envelope_id

The link of the route in the view

<%= link_to "Click here", user_pledge_document_path(:envelope_id => @envelope_id), :target => "_blank" %>

An example of the URL in the browser

http://localhost:3000/users/3/pledges/117/documents/716726EF-8888-40B0-84D0-7AFD3CAB9291

Here is the controller where I am trying to access the envelope_id

# documents_controller.rb
def show
  envelope_id = params[:envelope_id]
  pp envelope_id
end

There is no output when I print the envelope_id variable to console. However, if I print something like the lender_id to console from the same URL and in the same controller action it works as expected.

How can I access the envelope_id in the URL params when I'm inside of the show controller action?

Aucun commentaire:

Enregistrer un commentaire