I am trying to use link_to_unless to control the style tags on a link. I have also mapped the URL to "www.somesite.com/fred". What I am trying to get to work is that I want the condition to be based on the controller. I want the result to be the same as long as any actions are within the controller.
It's a tab based interface with subtabs. When a user clicks on a subtab I don't want the main tab to loose the highlighting from the style. Since the tab and sub tabs actually map to controllers and actions this should be possible. Below is the code I am trying to use for the main tabs but I can't seem to get the condition to work right. In this case I wan the tab to be active when some goes to "www.somesite.com/fred" or "www.somesite.com/fred/page2" not when they go to "www.somesite.com/bob".
<%= link_to_unless( params[:controller] == "fred", "Fred", fred_url, :class => "tab") do link_to("Fred", fred_url, :class => "tab-active") end %>
So, where's your problem? First glance, it looks like everything is in the right spot.
Is it just backwards? What's not working correctly for you?
renderbox
ASKER
When i tested this out I found the problem I am running into is that I am picking up the name of the "real" controller and not the one it is mapped to.
I'd like to the result to be one result from http://mysite.com/fred and http://mysite.com/fred/new and the other result from http://mysite.com/bob of http://mysite.com/foo. The problem I am noticing is that since fred_url, bob_url and foo_url use the same real :controller I don't get the result I am looking for.
This seems to be my misunderstanding of how to get the mapped URL instead of the real URL to check against. How would I make the check on a mapped URL?
renderbox
ASKER
Here is the improved version of my question.
In "http://mysite.com/XXXXX" how would I query XXXXX to see what it's value is when http://mysite.com/XXXXX is a mapped URL?
Is it just backwards? What's not working correctly for you?