Do you actually need a post, or do you just need rails to think it is
a post? If the latter will work, try passing in ‘_method’ => :post.
I seem to remember that this is how you can trick controllers into
thinking it’s a post request but I am not 100% sure. Another option
would be through rjs / ajax, but I have not done it. I am not sure if
the browser would consider an automated post a security issue.
That redirect_to looks like it would do it (if _method does/still
works). Post_via_redirect is used in integration tests so I don’t
really know if / how that would work in a standard controller, but I’m
fairly sure it won’t do what you want. The problem you are running into
here is not a rails limitation but an http limitation. The only way to
redirect in HTTP is a 302 and that is performed as a get request. If
you want post you can fake the controller out or use javascript. Is it
possible that you are hitting a design problem? Seems to me that if you
are having to post back to your own application then you may be going
the long way around. Can you not save the needed info in the session or
call the wanted method from your current method then render the result?
The application has a user dashboard that displays orders over a date
range. The date range can be altered by selecting week and year values
then pressing a submit button that causes a post request that the
controller method handles causing the dashboard to display the
selected week/year data. Once the date range is selected the user can
then modify the data. Once the changes to the data are complete I was
trying to return the view to the selected week/year values to provide
visual confirmation of the changes rather than just returning to the
default settings which correspond to today's week/year. Hence the
problem associated with using a redirect as a post request.
Yes - probably can - I was really just using the post/get difference
to separate the default state from the custom state. So I guess I
could use the parameters to differentiate the states.