Redirect_to restful-ful resource create action


What’s a neat way to redirect_to the create action of a restful
resource? Unless the request is POST, you fall through to the index

For example: a logged out user submits the following a comment form.

<% form_for @post, posts_path(@topic) -%>
<!-- stuff -%>
<% end -%>

Next request, the authorization filter detects they are not logged in.

somewhere a method in application.rb

unless @user.logged_in?
session[:redirection] = params
redirect_to :action => ‘login’ and return false

The logged-out user submits the login form, and the next request the
controller logs them in and attempts to perform the action the user
was orginally performing - POSTing a comment.

somewhere in ApplicationController.welcome(user)

redirection = session[:redirection] || home_url
redirect_to redirection # FAILS

redirection.inspect => { :controller => ‘posts’, :action =>

‘create’, :post => { :body => blah … } }

Because topics and posts are restful resources, the user is redirected
to the index action of the posts controller posts, not the create
action of the posts controller. This is because the restful route
generator is getting a POST request from redirect_to.

What’s a neat way round this (as opposed to hacking in a before_filter
or rewriting my index action)?

Thanks for looking,

PS I’m on 1.2.5 btw.