Hi all, I''m looking for a way to do the reverse of what the named route helpers do. Namely: Given routes: map.foo ''/foo/:id'', :controller => ''foo'', :action => ''show'' map.bar ''/bar/:id'', :controller => ''bar'', :action => ''show'' Given urls: /foo/1 /bar/1 I''d like to be able to do something like this in my layout: if requested_foo_path # ... show something specific to foo elsif requested_bar_path # ... show something specific to bar end There''s probably a better way to do this, but I''m new to rails so any help appreciated. Thanks!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Playing around I came up with this solution for now: map.foo ''/foo/:id'', :controller => ''foo'', :action => ''show'', :showing_foo => true map.bar ''/bar/:id'', :controller => ''bar'', :action => ''show'', :showing_bar => true if params[:showing_foo] # ... show something specific to foo elsif params[:showing_bar] # ... show something specific to bar else # ... show something generic end I''d still like to know if there is a better way though. If anyone has any info I''d appreciate learning the "Rails Way" to solve this problem, if that is not it. Thanks!! -dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Dave, On Sat, 2009-04-04 at 06:27 +0200, Dave Cantrell wrote:> There''s probably a better way to do this, but I''m new > to rails so any help appreciated.I''m not sure if this is what you''re looking for, but views get ''knowledge'' of their ''source'' via controller.controller name and controller.action_name. So you can do: if controller.controller_name == ''foo'' # ... show something specific to foo elsif controller.controller_name == ''bar'' # ... show something specific to bar end If you want to make the code specific to both controller and action you can do: if controller.controller_name == ''foo'' && controller.action_name =''show'' HTH, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bill walton wrote:> I''m not sure if this is what you''re looking for, but views get > ''knowledge'' of their ''source'' via controller.controller name and > controller.action_name.Thanks Bill! I actually knew about that and wrote a similar capability for some ASP work I do at work in my day job. Argh. Can''t believe I didn''t think of that this time. Goes to show what happens when most of your hobby coding is between 10pm and 1am... Thanks again, worked perfectly! -dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Dave, On Sun, 2009-04-05 at 05:14 +0200, Dave Cantrell wrote:> bill walton wrote: > > I''m not sure if this is what you''re looking for, but views get > > ''knowledge'' of their ''source'' via controller.controller name and > > controller.action_name. > > Thanks Bill! I actually knew about that and wrote a similar capability > for some ASP work I do at work in my day job. Argh. Can''t believe I > didn''t think of that this time. Goes to show what happens when most of > your hobby coding is between 10pm and 1am...;-) Yep!> Thanks again, worked perfectly!You''re welcome. Glad it helped. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alternatively, you can just use the current_page? method: if current_page? foo_url #do some ish elsif current_page? bar_url # other stuff... On Apr 4, 12:27 am, Dave Cantrell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > I''m looking for a way to do the reverse of what the named route helpers > do. Namely: > > Given routes: > > map.foo ''/foo/:id'', :controller => ''foo'', :action => ''show'' > map.bar ''/bar/:id'', :controller => ''bar'', :action => ''show'' > > Given urls: > > /foo/1 > /bar/1 > > I''d like to be able to do something like this in my layout: > > if requested_foo_path > # ... show something specific to foo > elsif requested_bar_path > # ... show something specific to bar > end > > There''s probably a better way to do this, but I''m new to rails so any > help appreciated. > > Thanks!! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
pharrington wrote:> Alternatively, you can just use the current_page? method: > > if current_page? foo_url > #do some ish > elsif current_page? bar_url > # other stuff...Hey, I like that too -- thanks! -dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
One final thing - you can also pass extra params in :requirements - thus: map.resource :foos, :requirements => { :extra => ''foo'' } will add :extra => ''foo'' to the incoming params. I''m not 100% sure if this works on map.connect style routes, but if it doesn''t, it''s probably a bug. --Matt Jones On Apr 6, 10:18 pm, Dave Cantrell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> pharrington wrote: > > Alternatively, you can just use the current_page? method: > > > if current_page? foo_url > > #do some ish > > elsif current_page? bar_url > > # other stuff... > > Hey, I like that too -- thanks! > > -dave > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---