Hello,
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
action.
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
  end
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,
Dave
PS I''m on 1.2.5 btw.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---