I''m under the gun and need a little help, please. My application is multi-layered, like so: Programs Kits Parts So when a user hits the Back button on a Parts/show page, I want them to return to the Kit that Part belongs to. When they hit Back on the Kit page, they should return to the Program page that Kit belongs to. Is there an existing way to do this? I''m thinking maybe some sort of stack passed in the @session variable, but I don''t want to reinvent an existing wheel. It would also be nice if I could convince the browser not to cache the pages, in case the user hit the browser''s back button. Any advice greatly appreciated! Regards, JJ
Hi John, On 8.2.2005, at 01:06, John Johnson wrote:> I''m under the gun and need a little help, please. > > My application is multi-layered, like so: > > Programs > Kits > Parts > > So when a user hits the Back button on a Parts/show page, I want them > to return to the Kit that Part belongs to. When they hit Back on the > Kit page, they should return to the Program page that Kit belongs to.I think you''re in dangerous waters when you want to change how the back button behaves. Users expect to come to the previous page they visited when they click the back button, not to some random page site author wants them to see. Even if your executives really want you to, *don''t break the back button* [1]. That said, rails can''t really control your browser behavior. Actually, I''m not even sure if JavaScript can be used to accomplish what you''re looking for (I hope not). Help your visitors by providing them clear user interface and information architecture. Consider using breadcrumbs [2] to give them a clue about where they are and a way to get higher in the hierarchy. But for heaven''s sake (pardon my repetition), leave the back button alone. //jarkko [1] http://www.smart.net/~dsb/2003/design/webstyle/DontBreakBackButton.html [2] http://www.usabilityfirst.com/glossary/main.cgi? function=display_term&term_id=786> > Is there an existing way to do this? > > I''m thinking maybe some sort of stack passed in the @session variable, > but I don''t want to reinvent an existing wheel. > > It would also be nice if I could convince the browser not to cache the > pages, in case the user hit the browser''s back button. > > Any advice greatly appreciated! > > Regards, > JJ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 08-Feb-2005, at 05:15, Jarkko Laine wrote:> On 8.2.2005, at 01:06, John Johnson wrote: >> So when a user hits the Back button on a Parts/show page, I want them >> to return to the Kit that Part belongs to. When they hit Back on the >> Kit page, they should return to the Program page that Kit belongs to. > > I think you''re in dangerous waters when you want to change how the > back button behaves. Users expect to come to the previous page they > visited when they click the back button, not to some random page site > author wants them to see. Even if your executives really want you to, > *don''t break the back button* [1].Actually, that''s what I''m trying to do :-) When on a Kit page, and I click on one of the Parts in that kit, I am taken to parts/show. When I click the Back link on that page, it takes me to parts/list, not kits/how/1. Which, as you say, is counter-intuitive.> > [1] > http://www.smart.net/~dsb/2003/design/webstyle/ > DontBreakBackButton.html > [2] > http://www.usabilityfirst.com/glossary/main.cgi? > function=display_term&term_id=786 >Thanks for the links, will have a look. Regards, JJ
On 8.2.2005, at 16:02, John Johnson wrote:> When on a Kit page, and I click on one of the Parts in that kit, I am > taken to parts/show. When I click the Back link on that page, it takes > me to parts/list, not kits/how/1. Which, as you say, is > counter-intuitive.A-ha, but now we''re talking about a "Back" link, not the browser back button, right? :-) You can of course control the links on your pages. One way to do this is to set @session["return_to"] in the kit page and then change your link to point to @session["return_to"]. Of course, if you think that link should always point to the kit page, you can change it to be something like this: <%= link_to "Back", :controller => "kits", :action => "show", :id => @part.kit_id %> (this assumes you have "belongs_to :kit" in your part model) //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 08-Feb-2005, at 09:13, Jarkko Laine wrote:> > On 8.2.2005, at 16:02, John Johnson wrote: > >> When on a Kit page, and I click on one of the Parts in that kit, I am >> taken to parts/show. When I click the Back link on that page, it >> takes me to parts/list, not kits/how/1. Which, as you say, is >> counter-intuitive. > > A-ha, but now we''re talking about a "Back" link, not the browser back > button, right? :-) > > You can of course control the links on your pages. One way to do this > is to set @session["return_to"] in the kit page and then change your > link to point to @session["return_to"]. Of course, if you think that > link should always point to the kit page, you can change it to be > something like this: > > <%= link_to "Back", :controller => "kits", :action => "show", :id => > @part.kit_id %> > > (this assumes you have "belongs_to :kit" in your part model) >Sorry, realized another snafu. A part can be in many kits, so after part/show is called, you won''t know which Kit to return to. I''ll look into the breadcrumb links. Thanks again! Regards, JJ
On 8.2.2005, at 16:56, John Johnson wrote:>> > Sorry, realized another snafu. A part can be in many kits, so after > part/show is called, you won''t know which Kit to return to.OK, then you might be best-off using @session["return_to"] or some other way to sneak the kit id to the part/show page. The downside of @session["return_to"] is that if you want to sneak in multiple levels of links, you need some additional hacking. However, here''s a simple demonstration on how you can use it for a simple back link: kits_controller: def show @session["return_to"] = @request.request_uri ... end parts_controller: def show @back_uri = @session["return_to"] @session["return_to"] = nil ... end parts/show.rhtml: <%= link_to "Back" @back_uri %> With this logic, you can create a whole breadcrumbs path (aka context bar). It''s a whole lot easier when you don''t have many-to-many relationships, tho. I''d suggest using something like "Back to kit XXX" instead of plain "Back", tho, to add a bit more context to the link. I would also consider creating a helper method for a context bar creation. Feel free to ask more about this if you''re interested. //jarkko> I''ll look into the breadcrumb links. > > Thanks again! > > Regards, > JJ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails