Mark
Mark

Reputation: 6445

Rails - redirect_to not sending params as intended

I have the following line of code:

redirect_to dynamic_page_path(page), corporate_contact_form: 'bla'

When I trigger this redirect and check my logs, it is being sent without the corporate_contact_form param, just the page.

I've checked the docs and believe I've entered all that's needed, however apparently not. Any help is appreciated.

Upvotes: 2

Views: 626

Answers (3)

Rafael Costa
Rafael Costa

Reputation: 1471

Well, it seems to me that you mixed the syntaxes, which could be:

redirect_to controller: 'dynamic_page', action: 'edit', corporate_contact_form: 'bla'

or

redirect_to dynamic_page_path(page, corporate_contact_form: 'bla')

This link should be helpful for you.

Upvotes: 1

oolong
oolong

Reputation: 675

I think you just have a syntax problem. You need to include the params you want to send as part of the args for your path helper. It should be:

redirect_to dynamic_page_path(page, corporate_contact_form: 'bla')

Upvotes: 0

danirod
danirod

Reputation: 350

Place your parameters inside the flash:

redirect_to dynamic_page_path(page), flash: { corporate_contact_form: 'bla' }

Only a few keys can be used outside the flash: :alert and :notice. That is why you might find in the docs things like:

redirect_to dynamic_page_path(page), notice: 'Hello'

Not all parameters can be placed without a flash, though.

Upvotes: 0

Related Questions