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.
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.
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.
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).
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:
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
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).