Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Modifying parameters on request doesn't update params object #160

Open
azach opened this issue Jul 30, 2013 · 2 comments
Open

Modifying parameters on request doesn't update params object #160

azach opened this issue Jul 30, 2013 · 2 comments

Comments

@azach
Copy link

azach commented Jul 30, 2013

It seems that modifying the parameters on the request directly won't end up modifying the parameters in the controller since it's memoized.

This is an issue when you have an external class the modifies the request object and then uses the parameters in a subsequent action. As a simplified example:

def create
  UserRedirector.set_redirect(request)
  redirect_to params[:redirect_to] # params != request.params here
end
# not in a controller context
class UserRedirector
  def self.set_redirect(request)
    request.params[:redirect_to] = '/some-place'
  end
end

Right now we're using a workaround to explicitly set the params to request.params after the action so the cache is updated, e.g.:

def create
  UserRedirector.set_redirect(request)
  params = request.params
  redirect_to params[:redirect_to] # params != request.params here
end
@thijsnado
Copy link

I have a similar issue, params update correctly but don't propagate to tests:

   # in controller
  def some_action
    params[:some_attr] = 'foo'
    redirect_to params[:some_attr] # works fine
  end

  # in test
  def test_some_action
    get :some_action
    assert_equal 'foo', request.params[:some_attr]
  end

@thijsnado
Copy link

ok, so, modifying params works, passing request.params won't work in your case. For my tests, I was able to fix by doing @controller.params[:some_attr] in the test

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants