Beginners life with Ruby and Rails

Duhh… Did I wrote I’m new to Ruby and Rails? Yes? I’m really new :-)))

I was trying to get use from link_to_unless_current. It works as stated in docs (generates link unless link would point to current, just rendered page). But when link is not rendered, it does not mean, that text does not appear…


link_to_unless_current ("Go here", {:controller => "some", :action => "current")

returns link to some/current (<a href=’some/current’>Go here</a>) unless this is current page, which results in plain text Go here

In documentation this helper is defined:

link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block)

And I needed some time to catch, that &block, which result can be returned from helper needs to be declared outside of parenthesis. Like that:

link_to_unless_current ("Go here", {:controller => "some", :action => "current") {}

As result this helper returns link to some/current unless we are rendering this page. In that case helper returns empty string (did You notice empty {} at the end?). That was it.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.