Forum: Ruby on Rails disable link on two conditions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kim (Guest)
on 2007-03-13 19:43
(Received via mailing list)
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
Philip H. (Guest)
on 2007-03-13 19:59
(Received via mailing list)
>
> 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
Steve R. (Guest)
on 2007-03-13 20:34
(Received via mailing list)
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 G. wrote:
> Pages" , :controller => 'page', :action => 'list'%>
> --no link is ever displayed
>
> any suggestions. Code examples are always helpful.
>
> Thanks in advance, K
>
>
> >
>
>

--
View this message in context:
http://www.nabble.com/disable-link-on-two-conditio...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
Kim (Guest)
on 2007-03-13 20:44
(Received via mailing list)
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
Rob B. (Guest)
on 2007-03-13 22:04
(Received via mailing list)
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
removed_email_address@domain.invalid
Kim G. (Guest)
on 2007-03-14 00:19
(Received via mailing list)
Thanks, yes it does get me were I was trying to go.

On 3/13/07, Rob B. <removed_email_address@domain.invalid> wrote:
> >>> <%= link_to_unless @page.nil? or current_page?, "My ICA
> >> Consider using @page.blank? instead of @page.nil?. Also, consider
> >> #removed_email_address@domain.invalid?
> >
> > Thanks,
> <%= link_to_unless( @page.nil?,"",{}) do link_to_unless_current "My
>
>
> Rob B.          http://agileconsultingllc.com
> removed_email_address@domain.invalid
>
>
>
> >
>


--
Kim G.
removed_email_address@domain.invalid

"We are all stakeholders in the Karma economy."
This topic is locked and can not be replied to.