From: "David A. Black" Date: 2008-05-25T09:27:10+09:00 Subject: Re: Railsy Question about redefining ruby methods... Hi -- On Sat, 24 May 2008, Xeno Campanoli wrote: > Please this is a Ruby question, not, at least as the main focus, a rails one, > as you'll see if you read all the way through. Well, if my answer is correct, it's a very Rails-specific question :-) > Say, I've got a case in Rails where I want all my links to be prepended with > something like ~u1/rrsw/thingies so I can see http://host/~u1/rrsw/thingies > and http://host/~u2/rrsw/thingies instead of http://host:9001/thingies and > http://host:9002/thingies for a rails tool that is used by some n projects. > The rails part is apparently not configurable, so I'm looking at redefining > rails methods like link_to to stick the path in there. This should be > reasonable, but I'm stuck on a ruby problem: > > I want to redefine the link_to method so it's seen in its new guise in all > the places where it's presently used. It seems to make most sense to put the > new redefinition in the module ApplicationHelpers, but I believe that may > short circuit the access, as I'm not seeing the example I put in which always > puts out a traceable constant, resulting in the expected changes in my test > web pages. So, and here is the question: > > Can anyone suggest how I should specify an appropriately available method for > the correct module inside another module so that it overrides the original in > the fashion I desire? I presume this is a simple problem, as it's what > people do all the time in OO right? I'm still a little green on these > patterns yet I think. Have a look at relative_url_root, which I believe (though I haven't used it in a while) does what you want. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 23-26 London (Skills Matter) See http://www.rubypal.com for details and updates!