On Mar 13, 2007, at 2:43 PM, Kim wrote:
<%= link_to_unless( @page.nil?,“”,{})do link_to_unless_current
If you tail your development.log, it should give you an idea
The problem is that the things I have tried are not formatted
correctly, thats what I am looking for.
How do I use two conditions in the link_to_unless or if I can’t, how
can I use the block statement in link_to_unless to then call
link_to_unless_current, or any other suggestions on how to disable a
link depending on two conditions.
Thanks,
Kim
Your problem is initially using ‘or’ which is very low precedence:
<%= (link_to_unless @page.nil?) or (current_page?, “My ICA
Pages” , :controller => ‘page’, :action => ‘list’) %>
–gives me errors
With the precedence made explicit, the reason for errors should
become obvious.
<%= link_to_unless( @page.nil?,“”,{}) do link_to_unless_current “My
ICA Pages” , :controller => ‘page’, :action => ‘list’%>
–no link is ever displayed
Do you have a test? I suspect that you don’t, but I’ll leave that as
an exercise.
<%= link_to_unless(@page.nil? || current_page?(:controller =>
‘page’, :action => ‘list’),
“My ICA Pages”, :controller => ‘page’, :action =>
‘list’) %>
Which will be a link having anchor text “My ICA Pages” or just the
plain text if either condition is true. If you want different text
for the non-link case:
<%= link_to_unless(@page.nil? || current_page?(:controller =>
‘page’, :action => ‘list’),
“My ICA Pages”, :controller => ‘page’, :action =>
‘list’) {|txt| “No link to #{txt}”} %>
If you want nothing at all, then use:
<% unless @page.nil? || current_page?(:controller => ‘page’, :action
=> ‘list’) %>
<%= link_to(“My ICA Pages”, :controller => ‘page’, :action =>
‘list’) %>
<% end %>
Does that get you where you’re trying to go?
-Rob
Rob B. http://agileconsultingllc.com
[email protected]