Hi List,
I didn''t like the way store_location worked in rails. It
doesn''t know
you''ve pushed the "back" button, and it always returns to the
top of a
page. On a large page, the part you were looking at would no longer be
on the screen.
People try to deal with this using an AJAX hack, but it seems to me that
the proper way to fix it is to store the return location when a link or
form is activated, rather than before.
*link_modal* is a version of link_to that adds
"?ret=<URL>.L<LINK_ID>"
to the link. It takes an extra "link_id" argument that sets the ID
attribute of the A element to L<LINK_ID>". I usually derive this ID
programaticaly, from the ID of the record that this link pertains to.
Set it to "nil" if you don''t use it. It''ll make a
garbage link if you
don''t set the ID.
*
modal_form* creates a hidden form field named "ret", set as above.
*
store_return* is a filter that looks for @params[''ret''] and
sets
@session[''return-to''] with its value (substituting
''#L'' for the ''.L'' I
used to encode the anchor).
If I set store_return to be a /before filter for the application
controller,/ it does the equivalent of a store_location every time
"ret"
is passed in by a GET or POST.
redirect_back_or_default will then redirect to the value passed in as
"ret". Since this includes an internal anchor on a page, it will
return
to the proper line on a long page.
When using this scheme, user code never calls store_location. Link_modal
and modal_form are the only means necessary to set the return page.
This also puts the responsibility for storing what is returned to more
/in the view /rather than the controller. It seems to me that this does
belong in the view and that we might have had some MVC paradigm breakage
previously.
I did this all in my application helper, except for the line connecting
the before filter to the application. I''ve attached the code to this
message. Pardon my tyro''s ruby. This is copyright (C) 2005 Perens LLC,
licensed under the same license as Rails.
Thanks
Bruce
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails