views:

61

answers:

1

For the life of me, I can't figure out (or find the right text to search) how to create a link that looks like this:

<a href="/publisher" class="button first"><span>This text will be hidden</span></a>

There's a similar example in the link_to API, but it doesn't quite get to what I need. I don't want my anchor tag to have any text (all text will reside in the nested span) and I want to link to a route named publisher_root.

I'm tired of banging my head on this, so any help would be much appreciated.

UPDATE: As mentioned in my comment below, HAML is also in play here. I eliminated it originally because it seemed like nothing more than an additional complexity. Since it appears to be at the crux of the issue, though, I've added the tag and here's my code:

#masthead.container
  %h1
    != image_tag( 'home-masthead.png' )
  %p
    - link_to publisher_root, :class => 'button first' do
      %span Link Text
+4  A: 

You need to use the block form of the link_to helper. This will do what you require:

<% link_to publisher_root, :class => 'button first' do %>
  <span>This text will be hidden</span>
<% end %>

HAML version:

= link_to publisher_root, :class => 'button first' do 
  %span This text will be hidden
John Topley
Hmmm. I actually did try that, but I get an error about `publisher_root`. I've run `rake routes` and it does exist so that's why I assumed I was doing it wrong. I'm using HAML to get this done, so maybe there's something going on there that I don't understand. I'll go back and take another look. Thank you.
Rob Wilkerson
I tried it myself with one of my own projects (using ERB) and it did work. As you say, perhaps it's a HAML issue.
John Topley
Argh. Sometimes the obvious is the hardest to see. All I was missing was the `_url` suffix: `link_to publisher_root_url, :class => 'button first' do ...` Thanks for your help.
Rob Wilkerson