# Link\_to\_remote html\_options example

**URL:** <https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781>\
**Category:** Rails\
**Created:** [September 15, 2006, 12:41pm UTC](https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781 "2006-09-15T12:41:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cliffeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df705f/32.png) [@cliffeh](https://www.ruby-forum.com/u/cliffeh)\
**Post date:** [September 15, 2006, 12:41pm UTC](https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781/1 "2006-09-15T12:41:40Z")

</div>

Can anyone give me an example of using html\_options with  
link\_to\_remote? I’d like to set (for instance) the CSS Class on the  
resulting link. I’ve tried this sort of thing:

\<%= link\_to\_remote ‘Text’, :url =\> {:action =\> ‘myaction’, :id =\>  
myobject.id}, :html\_options =\> {:class =\> ‘myclass’} %\>

Everything works OK except that it ignores the HTML options.

Thanks,  
Cliffe

---

<div class="post-metadata">

**Author:** ![cliffeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df705f/32.png) [@cliffeh](https://www.ruby-forum.com/u/cliffeh)\
**Post date:** [September 15, 2006, 12:51pm UTC](https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781/2 "2006-09-15T12:51:42Z")

</div>

cliffeh wrote:

> Can anyone give me an example of using html\_options with  
> link\_to\_remote? I’d like to set (for instance) the CSS Class on the  
> resulting link. I’ve tried this sort of thing:
> 
> \<%= link\_to\_remote ‘Text’, :url =\> {:action =\> ‘myaction’, :id =\>  
> myobject.id}, :html\_options =\> {:class =\> ‘myclass’} %\>

drop the :html\_options =\> part…  
eg.

\<%= link\_to\_remote ‘Text’, :url =\> {:action =\> ‘myaction’, :id =\>  
myobject.id}, :class =\> ‘myclass’ %\>

I think that should work…  
G

> Everything works OK except that it ignores the HTML options.
> 
> Thanks,  
> Cliffe
> 
> >

–  
about me:  
My greatest achievement was when all the other  
kids just learnt to count from 1 to 10,  
i was counting (0…9)

- gustav.paul

---

<div class="post-metadata">

**Author:** ![cliffeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df705f/32.png) [@cliffeh](https://www.ruby-forum.com/u/cliffeh)\
**Post date:** [September 15, 2006, 12:55pm UTC](https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781/3 "2006-09-15T12:55:43Z")

</div>

> Can anyone give me an example of using html\_options with  
> link\_to\_remote? I’d like to set (for instance) the CSS Class on the  
> resulting link. I’ve tried this sort of thing:
> 
> \<%= link\_to\_remote ‘Text’, :url =\> {:action =\> ‘myaction’, :id =\>  
> myobject.id}, :html\_options =\> {:class =\> ‘myclass’} %\>

In your case Rails cannot tell where does options parameter hash end and  
html\_options hash begins.

Try that:

\<%= link\_to\_remote ‘Text’, {:url =\> {:action =\> ‘myaction’, :id =\>  
myobject.id}}, {:class =\> ‘myclass’} %\>

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![cliffeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df705f/32.png) [@cliffeh](https://www.ruby-forum.com/u/cliffeh)\
**Post date:** [September 15, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/link-to-remote-html-options-example/68781/4 "2006-09-15T13:09:47Z")

</div>

> drop the :html\_options =\> part…  
> eg.
> 
> \<%= link\_to\_remote ‘Text’, :url =\> {:action =\> ‘myaction’, :id =\> myobject.id}, :class =\> ‘myclass’ %\>

> I think that should work…

You are right about :html\_options, but this still will not work,  
because ‘options’ hash will  
swallow both :url and :class leaving ‘html\_options’ empty.  
When using html\_options, make sure Rails can tell them from options,  
i.e. use curly  
braces for options:

\<%= link\_to\_remote ‘Text’, {:url =\> {:action =\> ‘myaction’, :id =\>  
myobject.id}}, :class =\> ‘myclass’ %\>

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
