0

I would like to redirect from one action to another in a same controller.

Suppose I have a private method my_params that returns an ActionController::Parameters instance. It looks like { some_param: 'a', another_param: 'b' }.

Let's say I want to redirect from :action_1 from :action_2 passing params.

When I try to do redirect_to :action, my_params, Rails complains:

syntax error, unexpected end-of-input, expecting keyword_end

Normally, I would write something like,

redirect_to :action, some_param: 'a', another_param: 'b'`

but I cannot do so in this case, because I want to pass my_params.

Is there a Rails way to do this? Or any other suggestions?

Edit

This is not a duplicate because I want to pass in a param that is already an instance of ActionController::Parameters.

mc9
  • 6,121
  • 13
  • 49
  • 87
  • possible duplicate of [Rails: call another controller action from a controller](http://stackoverflow.com/questions/5767222/rails-call-another-controller-action-from-a-controller) – Ryan K Apr 16 '15 at 00:39

1 Answers1

4

You can pass your current my_params parameters hash to the redirect_to method and only update (merge) the values you want to change.

redirect_to my_params.merge(action: :action_1)
spickermann
  • 100,941
  • 9
  • 101
  • 131