Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails redirect_to https while keeping all parameters

I'm redirecting to https like so:

redirect_to :protocol => 'https://', :status => :moved_permanently

However, the parameters don't go through like this. I can pass specific parameters through like this:

redirect_to :protocol => 'https://', :status => :moved_permanently, :param1 => params[:param1], :param2 => params[:param2]

How would I make it so that it just passes through every parameter on the url instead of having to explicitly declare each parameter?

like image 487
Eric Yang Avatar asked Jun 28 '12 21:06

Eric Yang


1 Answers

With Rails 4.2 and above, passing the whole params hash will result in adding ?controller=foo&action=bar to the querystring. Instead, you should do this:

redirect_to protocol: 'https', params: request.query_parameters
like image 101
seanlinsley Avatar answered Sep 21 '22 06:09

seanlinsley