disable link on two conditions

I want to disable my navigation depending on two conditions: 1) the
page is not the current one, 2) the page is not in the session.

I have tried:
<%= link_to_unless @page.nil? or current_page?, "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--gives me errors
<%= link_to_unless( @page.nil?,"",{})do link_to_unless_current "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--no link is ever displayed

any suggestions. Code examples are always helpful.

Thanks in advance, K

I want to disable my navigation depending on two conditions: 1) the
page is not the current one, 2) the page is not in the session.

I have tried:
<%= link_to_unless @page.nil? or current_page?, "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--gives me errors
<%= link_to_unless( @page.nil?,"",{})do link_to_unless_current "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--no link is ever displayed

any suggestions. Code examples are always helpful.

Haven't tried it, but maybe...

link_to_unless (@page.nil? || current_page?(params)), "blah blah blah"....

-philip

Consider using @page.blank? instead of @page.nil?. Also, consider inserting
this above the statement:

<% RAILS_DEFAULT_LOGGER.debug("page was: #{@page} and current_page? is
#{current_page?}) %>
<% RAILS_DEFAULT_LOGGER.debug("My or expression evaluates to: #{@page.nil?
or current_page?}) %>
<% RAILS_DEFAULT_LOGGER.debug("My || expression evaluates to: #{@page.nil?

current_page?}) %>

If you tail your development.log, it should give you an idea what's going
on.

Kim Griggs wrote:

Sorry, should have explained myself better.

@page is a session variable so @page.nil? is correct. I want to check
if the session contains the page (which is a model in my app)

I am well aware on how to debug, thanks anyways.

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

Kim Griggs wrote:

I want to disable my navigation depending on two conditions: 1) the
page is not the current one, 2) the page is not in the session.

I have tried:
<%= link_to_unless @page.nil? or current_page?, "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--gives me errors
<%= link_to_unless( @page.nil?,"",{})do link_to_unless_current "My ICA
Pages" , :controller => 'page', :action => 'list'%>
--no link is ever displayed

any suggestions. Code examples are always helpful.

Thanks in advance, K

Consider using @page.blank? instead of @page.nil?. Also, consider inserting
this above the statement:

<% RAILS_DEFAULT_LOGGER.debug("page was: #{@page} and current_page? is
#{current_page?}) %>
<% RAILS_DEFAULT_LOGGER.debug("My or expression evaluates to: #...@page.nil?
or current_page?}) %>
<% RAILS_DEFAULT_LOGGER.debug("My || expression evaluates to: #...@page.nil?
>> current_page?}) %>

If you tail your development.log, it should give you an idea what's going
on.

Sorry, should have explained myself better.

@page is a session variable so @page.nil? is correct. I want to check
if the session contains the page (which is a model in my app)

I am well aware on how to debug, thanks anyways.

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 Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Thanks, yes it does get me were I was trying to go.