Degrading link_to_remote

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?

found it.

i added: :href => url_for(:action => ‘show_links’, :id => link_cat) to
the helper and it works beautifully.

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.

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

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.

Take a look at UnobtrusiveJavascript for rails.

http://www.ujs4rails.com/

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

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