link_to help in Rails 3.0.3

Is there a way to get link_to to generate a body-less anchor?

I have a CSS sprite which represents an “add” / “remove” button which I use, so I don’t want any body text. For example, I want something similar to this:

<a title=‘Add Attachment’ class=‘add_child’ onclick=‘add_asset_row'></a>

Using this does not work:

<%= link_to '#', :url => {:action => 'add_asset_row'}, :title => 'Add attachment', :class => 'add_child', :remote => true %>

Any suggestions?

Is there a way to get link_to to generate a body-less anchor?

Not sure I understand as what you ask for below isn't an anchor... ??

But maybe what you want is...

link_to_function '', 'add_asset_row()', :class => 'add_child'

Or if you really want a remote link just replace that '#' with '' and it should give you an empty link...

Philip Hallstrom wrote in post #979207:

Not sure I understand as what you ask for below isn't an anchor... ??

But maybe what you want is...

link_to_function '', 'add_asset_row()', :class => 'add_child'

Or if you really want a remote link just replace that '#' with '' and it should give you an empty link…

Using ‘’ with link_to forces it to use the href as the body. But, switching to link_to_function using ‘’ got rid of the body.

Thanks for the tip!

Now I need to figure out how to get it working with jQuery since I’m not using Prototype...

Edward Stembler wrote in post #979228:

Now I need to figure out how to get it working with jQuery since I’m not using Prototype…

Here’s how I got it to work using jQuery:

<%=link_to_function '', "$('#asset_rows').append('#{escape_javascript render(:partial => 'partials/asset_row', :locals => {:asset => Asset.new})}')", :title => 'Add Attachment', :class => 'add_child' %>

Now on to the “remove” button...

if you name your partial

partials/rows/asset

then you can use :object => Asset.new

instead of :locals => ...