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

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.

Walter

Best,

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 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 :slight_smile:

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
:wink:

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")

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,