As I''ve developed my application, I''ve developed a few
patterns for
maintaining forward flow in forms and providing actions that redirect
back to the same page. As I''ve moved forward, though, I''ve
found that
these patterns are inherently broken, mostly due to the dependence on
HTTP_REFERRER. At some point, I disabled HTTP_REFERRER in my browser.
Suddenly my site starts acting weird--this is no good.
What I had implemented was a few methods on my ApplicationController.
The first is redirect_to_last which boiled down to redirect_to
@request.env[''HTTP_REFERRER'']. I used it after, for instance,
processing a login when @session[''return_to''] wasn''t
set. This was
done since the login form appears on every page in a sidebar and
logins should return to where the user left off.
The second method just returned the HTTP_REFERRER and was used as a
target for form cancel buttons. Essentially, all of my forms have
cancel buttons which take the user back to the page they got to the
form from (done using js, not a form post). <%=cancel_button%> would
let me put one of these things anywhere. Effectively, it did the same
thing as the browser back button without interrupting forward flow in
the user''s experience.
Basically, I''m looking for a better way to accomplish these kinds of
goals. Both methods should default back to ''/'' if the referrer
is
unknown.
As an aside, I''ve got a hack that works, but it''s really ugly
and kind
of steps all over mvc. Essentially, I have (in ApplicationController):
helper_method :set_last
def set_last
@session[''last''] =
@request.env[''REQUEST_URI'']
end
and in my (only) layout rhtml file, at the very end, <% @controller.set_last
%>
Then I can use @session[''last''] like I used HTTP_REFERRER. If
its nil,
then I default to ''/''
The reason that I can''t use set_last as an after_filter is that I only
want full page requests to trigger it (excluding ajax requests and
dynamic image requests which are also subject to
ApplicationController''s filters). Putting it in the template solved
this, but it makes me feel like I''ve compromised something to do it.
There has to be a better way. Maybe someone here knows of it/can think of it.
Thanks,
Brian
--
The years ahead pick up their dark bags.
They move closer. There''s a slight rise in the silence
then nothing.
--
(If you''re receiving this in response to mail sent to
bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned
This is my new address,
but mail will be forwarded here indefinitely)