# Degrading link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/degrading-link-to-remote/65757>\
**Category:** Rails\
**Created:** [August 21, 2006, 6:56am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757 "2006-08-21T06:56:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 21, 2006, 6:56am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/1 "2006-08-21T06:56:51Z")

</div>

i have some items that use the link\_to\_remote helper and i would like  
them to also link directly to the page that they are calling if  
javascript is not available. i have tried putting the action and id in  
like i would with a regular link\_to helper but that didn’t work.

how can i accomplish this?

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 21, 2006, 7:02am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/2 "2006-08-21T07:02:59Z")

</div>

found it.

i added: :href =\> url\_for(:action =\> ‘show\_links’, :id =\> link\_cat) to  
the helper and it works beautifully.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 21, 2006, 7:18am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/3 "2006-08-21T07:18:22Z")

</div>

I’ve done this before, here is an example:

\<%= link\_to\_remote s.name, {:url =\> {:action =\> “view”, :id =\> s}},  
{:href =\> url\_for(:action =\> “index”, :id =\> s)} %\>

Note the extra braces to separate which hash is which. Actually I  
don’t think the braces arount :href are necessary, but I’m leaving them  
because I know this works because it’s cut and paste from an actual  
app.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 21, 2006, 7:26am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/4 "2006-08-21T07:26:22Z")

</div>

Link to remote allows you to add additional html attributes to the tag:

link\_to\_remote “Delete this post”, :update =\> “posts”,  
:url =\> { :action =\> “destroy”, :id =\> post.id },  
{:href =\> url\_for(…)}

Note the href above.

Hammed

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 26, 2006, 12:58pm UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/5 "2006-08-26T12:58:18Z")

</div>

Using tabs i had to put in the class name in to link\_to\_remote  
BTW. just to understand this definition for link\_to\_remote

name, options = {}, html\_options = {} - which means that there are 2  
types of options there which to be used like that { :update =\>  
“div\_name”, :url =\> {…}} and html\_options  
{:class =\> “class\_name”,:href =\> url\_for(…)}

So thats how I put in my class name

\<%= link\_to\_remote “Parent”,  
{:update =\> “tabs”,:url =\> {:action =\>  
“show\_parent”}},  
{:class =\> “active”} %\>  
BTW, if you are to disable class parameter you can send in nil ( :class  
=\> nil )

Note: Thats was not intended as tutorial - just something for me to  
remember in the future.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [August 26, 2006, 11:05am UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/6 "2006-08-26T11:05:53Z")

</div>

Take a look at UnobtrusiveJavascript for rails.

[http://www.ujs4rails.com/](http://www.ujs4rails.com/)

It’s perfect for what you’re looking to do.  
Ian.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/degrading-link-to-remote/65757/7 "2006-09-04T14:46:13Z")

</div>

> i have some items that use the link\_to\_remote helper and i would like  
> them to also link directly to the page that they are calling if  
> javascript is not available. i have tried putting the action and id in  
> like i would with a regular link\_to helper but that didn’t work.
> 
> how can i accomplish this?

Forms:  
\<%= form\_remote\_tag(:url =\>{:action =\> “myaction”}, :html =\> {:action  
=\> url\_for(:action =\> “myaction”), :id =\> “myform”}) %\>

Links:  
link\_to\_remote(“mylink”,{:url =\> {:action =\> “myaction”}},{:href =\>  
url\_for(:action =\> “myaction”)})

Best regards

Peter De Berdt
