Walter Lee Davis
2010-Dec-18 21:54 UTC
Is there a simple test for "am I at the root or not" in a view?
I have a very simple request from my client that there be a larger logo on the home page than every other page in the site. I did something fairly kludgy to make it work quickly -- put a bare variable in the application controller: at_root = false and then in my home method put at_root = true and test for that in the view. But this seems like three times too much work to me, plus it puts view-related stuff in the controller. Is there a simple test I can perform in the view, so I can know if the current request == :root or not? Google has been unhelpful, probably because the words in my question are too general. Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-18 22:53 UTC
Re: Is there a simple test for "am I at the root or not" in a view?
Walter Davis wrote in post #969331:> I have a very simple request from my client that there be a larger > logo on the home page than every other page in the site. I did > something fairly kludgy to make it work quickly -- put a bare variable > in the application controller: > > at_root = false > > and then in my home method put > > at_root = true > > and test for that in the view. But this seems like three times too > much work to me, plus it puts view-related stuff in the controller. Is > there a simple test I can perform in the view, so I can know if the > current request == :root or not?You could use current_page? ; however, in your case, I''d probably simply declare a different layout for the home page.> > Google has been unhelpful, probably because the words in my question > are too general. > > WalterBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Walter Lee Davis
2010-Dec-19 04:05 UTC
Re: Re: Is there a simple test for "am I at the root or not" in a view?
On Dec 18, 2010, at 5:53 PM, Marnen Laibow-Koser wrote:>> and test for that in the view. But this seems like three times too >> much work to me, plus it puts view-related stuff in the controller. >> Is >> there a simple test I can perform in the view, so I can know if the >> current request == :root or not? > > You could use current_page? ; however, in your case, I''d probably > simply > declare a different layout for the home page.Hmmm. That seems like a lot of duplication, since the only thing I want to change is the name of the logo file. Thanks, Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-Dec-19 08:56 UTC
Re: Re: Is there a simple test for "am I at the root or not" in a view?
On 19 December 2010 04:05, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:>> You could use current_page? ; however, in your case, I''d probably simply >> declare a different layout for the home page. > > Hmmm. That seems like a lot of duplication, since the only thing I want to > change is the name of the logo file.Hardly lots... and you could DRY it... Alternatively, what about storing the logo filename in settings? (I''d recommend SettingsLogic). And then updating/overwriting the value in the home controller - similar to your own solution, but a bit more decipherable for The Next Developer (or you in six months :-) Or... if you really want to evaluate on every page, you can access @controller and the action name in the view - create a helper that compares it to the root_url to display whichever image you wish - this StackOverflow post might help if that''s the approach you want to take: http://stackoverflow.com/questions/960041/get-matching-route-from-url-in-rails-again> Google has been unhelpful, probably because the words in my question are too > general.Also, possibly, because you problem has so many possible solutions, and none of them "the right one"... just pick one that''s least smelly ;-) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Phillip
2010-Dec-20 00:45 UTC
Re: Is there a simple test for "am I at the root or not" in a view?
Create a method in application_helper.rb to compare the root path with request.env[''PATH_INFO''], returning the url of the appropriate logo (pass the root path and both logos in with the method call in your layout). logo_helper("/your root path/", "/images/big_logo.png", "/ images/small_logo.png") On Dec 18, 4:54 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> I have a very simple request from my client that there be a larger > logo on the home page than every other page in the site. I did > something fairly kludgy to make it work quickly -- put a bare variable > in the application controller: > > at_root = false > > and then in my home method put > > at_root = true > > and test for that in the view. But this seems like three times too > much work to me, plus it puts view-related stuff in the controller. Is > there a simple test I can perform in the view, so I can know if the > current request == :root or not? > > Google has been unhelpful, probably because the words in my question > are too general. > > Walter-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser
2010-Dec-20 02:33 UTC
Re: Is there a simple test for "am I at the root or not" in a view?
Phillip wrote in post #969461:> Create a method in application_helper.rb to compare the root path with > request.env[''PATH_INFO''], returning the url of the appropriate logo > (pass the root path and both logos in with the method call in your > layout). > > logo_helper("/your root path/", "/images/big_logo.png", "/ > images/small_logo.png")That really is the hard way of doing it. Just use current_page? . Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.