# Assign CSS class to Link to Remote

**URL:** <https://www.ruby-forum.com/t/assign-css-class-to-link-to-remote/96452>\
**Category:** Rails\
**Created:** [June 28, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/assign-css-class-to-link-to-remote/96452 "2006-06-28T21:00:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [June 28, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/assign-css-class-to-link-to-remote/96452/1 "2006-06-28T21:00:07Z")

</div>

I’m trying to get link\_to\_remote to assign a CSS class to the link it  
generates. My code is as follows:

\<%=  
link\_to\_remote “Show Full Info”,  
:update =\> “fullcontact” + reparray.last.to\_s,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s,  
:classname =\> “contactlink”  
%\>

Which produces this HTML:

Show Full Info

And I would like it to produce this HTML:

Show Full Info

I’ve also tried the code this way:

\<%=  
link\_to\_remote “Show Full Info”,  
{ :update =\> “fullcontact” + reparray.last.to\_s,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s},  
{ :classname =\> “contactlink” }  
%\>

(The only difference is the addition of the {}'s.) The result is the  
same.  
What am I doing wrong here? I don’t want to statically write the HTML  
into  
the view, which would work fine, but just isn’t as elegant as Ruby on  
Rails  
should be.

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [June 28, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/assign-css-class-to-link-to-remote/96452/2 "2006-06-28T23:04:40Z")

</div>

Thanks for the help, Daniel. The code you provided produced an error,  
(wrong number of arguments, 4 for 3), but it was your explanation that  
helped me the most. The correct code to do what I was looking for was  
actually:

\<%=  
link\_to\_remote “Show Full Info”,  
{ :update =\> “fullcontact” + reparray.last.to\_s,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s},  
{ :class =\> “contactlink” }  
%\>

The empty hash you had in the middle of the code was causing the error.  
Thanks for the help, again, Daniel, and I hope this helps anybody else  
who  
has this problem!

- David

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [June 28, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/assign-css-class-to-link-to-remote/96452/3 "2006-06-28T21:09:50Z")

</div>

If you go to the API page,  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M)  
000412, you’ll see that the signature for link\_to\_remote is

link\_to\_remote(name, options = {}, html\_options = {})

So, the secong argument is an options hash, and the last is the  
html\_options  
hash - html\_options is where you’d set the class. Your code should look  
like

link\_to\_remote “Show Full Info”,  
{ :update =\> “fullcontact” + reparray.last.to\_s,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s},

{},  
{ :class =\> “contactlink” }

Also notice that it’s :class, not :classname.

Hope this helps!

Daniel

* * *

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of David R.  
Sent: Wednesday, June 28, 2006 8:58 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] Assign CSS class to Link to Remote

I’m trying to get link\_to\_remote to assign a CSS class to the link it  
generates. My code is as follows:

\<%=  
link\_to\_remote “Show Full Info”,  
:update =\> “fullcontact” + reparray.last.to\_s ,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s,  
:classname =\> “contactlink”  
%\>

Which produces this HTML:

\<a  
href=“#” onclick=“new Ajax.Updater(‘fullcontact7’,  
‘/cm/full\_contact/7’,  
{asynchronous:true, evalScripts:true}); return false;”

> Show Full Info

And I would like it to produce this HTML:

\<a  
href=“#” class=“contactlink” onclick=“new Ajax.Updater(‘fullcontact7’,  
‘/cm/full\_contact/7’, {asynchronous:true, evalScripts:true}); return  
false;”

> Show Full Info

I’ve also tried the code this way:

\<%=  
link\_to\_remote “Show Full Info”,  
{ :update =\> “fullcontact” + reparray.last.to\_s,  
:url =\> “/cm/full\_contact/” + reparray.last.to\_s},  
{ :classname =\> “contactlink” }  
%\>

(The only difference is the addition of the {}'s.) The result is the  
same.  
What am I doing wrong here? I don’t want to statically write the HTML  
into  
the view, which would work fine, but just isn’t as elegant as Ruby on  
Rails  
should be.

Thanks,  
David
