Beginners life with Ruby and Rails
Posted on May 5, 2006 - Filed Under Ruby
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.
Popularity: 2% [?]
Hits for this post: 2527
Similar Posts
- form_tag and HTML options
- Generating data for AJAX req in Rails on the fly
- Empty nil
- Using non text values as arguments in functional tests
- Pagination, AJAX and GROUP BY
Comments
Leave a Reply


