I have two puzzlers regarding URLs. 1) Is there a way to get a component of the current URL? Specifically, I need to get the id. Yes, I an set it in the controller, but I''d like to avoid that. 2) I still haven''t found out how to generate a link that points to a static page in the public directory or a subdirectory. This must be a common case for things like help pages. Yet I don''t see how to do this when the app lives under a prefix, i.e., http://localhost:3000/myapp/mystaticpage.html Michael -- Michael Schuerig Thinking is trying to make up mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org for a gap in one''s education. http://www.schuerig.de/michael/ --Gilbert Ryle
Hi ! Michael Schuerig said the following on 2005-09-27 16:38:> 1) Is there a way to get a component of the current URL? Specifically, I > need to get the id. Yes, I an set it in the controller, but I''d like to > avoid that.params[:id] should do the trick. I might be misunderstanding what you want, though. params is a Hash that contains all the parameters that were in the request. For a GET of /admin/view/12?page=3, your params Hash would contain the following values: { :controller => ''admin'', :action => ''view'', :id => ''12'', :page => ''3'' }> 2) I still haven''t found out how to generate a link that points to a > static page in the public directory or a subdirectory. This must be a > common case for things like help pages. Yet I don''t see how to do this > when the app lives under a prefix, i.e., > http://localhost:3000/myapp/mystaticpage.htmlYou can use link_to with a text link: link_to ''Help'', ''mystaticpage.html'' That should do the trick. Bye ! François
On Wednesday 28 September 2005 05:09, François Beausoleil wrote:> Michael Schuerig said the following on 2005-09-27 16:38: > > 1) Is there a way to get a component of the current URL? > > Specifically, I need to get the id. Yes, I an set it in the > > controller, but I''d like to avoid that. > > params[:id] should do the trick. I might be misunderstanding what > you want, though. params is a Hash that contains all the parameters > that were in the request. For a GET of /admin/view/12?page=3, your > params Hash would contain the following values: > { :controller => ''admin'', :action => ''view'', :id => ''12'', :page => > ''3'' }Hm :-) Yes, I think that does it. I''m still a bit reluctant as I don''t like to refer to params[:id] in a helper method.> > 2) I still haven''t found out how to generate a link that points to > > a static page in the public directory or a subdirectory. This must > > be a common case for things like help pages. Yet I don''t see how to > > do this when the app lives under a prefix, i.e., > > http://localhost:3000/myapp/mystaticpage.html > > You can use link_to with a text link: > link_to ''Help'', ''mystaticpage.html''That gives me one of these link_to ''Help'', ''help.html'' -> http://localhost:3000/myapp/controller/action/help.html link_to ''Help'', ''/help.html'' -> http://localhost:3000/help.html The resulting URL I want is http://localhost:3000/myapp/help.html and I *don''t* want to write link_to ''Help'', ''/myapp/help.html'' As then I''d have to put the application prefix in several places. Which would be thoroughly wet (un-DRY). I had hoped there was a way to have routing solve this behind the scenes. Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn
> As then I''d have to put the application prefix in several places. Which > would be thoroughly wet (un-DRY). I had hoped there was a way to have > routing solve this behind the scenes.Why can''t you use named routes? Am I misreading? map.help ''/help/:page'' help_url :page => ''support.html'' -- rick http://techno-weenie.net
On Wednesday 28 September 2005 15:24, Rick Olson wrote:> > As then I''d have to put the application prefix in several places. > > Which would be thoroughly wet (un-DRY). I had hoped there was a way > > to have routing solve this behind the scenes. > > Why can''t you use named routes? Am I misreading? > > map.help ''/help/:page'' > > help_url :page => ''support.html''The major obstacle is that I don''t understand them... Say my help file is in public/help/help.html. Then I want help_url :page => ''help.html'' to give /help/help.html I''d like to omit the server part of the URL and, of course, it should resolve to public/help/help.html. Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn