Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7904 (new defect)

Opened 1 year ago

Last modified 1 year ago

[PATCH] DRY up link_to_remote for degradable URLs

Reported by: chuyeow Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: link_to_remote, javascript, ajax, degradation, degradable, URLs
Cc:

Description

I like to keep my links that make AJAX requests degradable in non-JavaScript browsers so I often find myself doing this:

link_to_remote 'Show details',
  { :url => { :action => 'show', :id => post.id } },
  { :href => url_for({ :action => 'show', :id => post.id }) }

The duplication of the URL in the options[:url] and html_options[:href] feels quite "un-DRY". Granted, it's not always true that the 2 parameters are the same, but I find that almost 90% of the time it is.

I've attached diffs that include tests against a patched link_to_remote that allows you to do just this instead (i.e. :href defaults to options[:url] instead of '#' unless it's specified).

link_to_remote 'Show details',
  { :url => { :action => 'show', :id => post.id } }

I hope this makes the cut so I can kill my PrototypeHelper monkey patch :).

Attachments

prototype_helper.with_degradation.diff (0.7 kB) - added by chuyeow on 03/24/07 14:41:08.
Diff that patches link_to_remote in prototype_helper.rb to be degradable in non-JS browsers
prototype_helper_test.with_degradation.diff (4.5 kB) - added by chuyeow on 03/24/07 14:43:47.
Diff that includes tests for the patch to link_to_remote in prototype_helper.rb

Change History

03/24/07 14:41:08 changed by chuyeow

  • attachment prototype_helper.with_degradation.diff added.

Diff that patches link_to_remote in prototype_helper.rb to be degradable in non-JS browsers

03/24/07 14:43:47 changed by chuyeow

  • attachment prototype_helper_test.with_degradation.diff added.

Diff that includes tests for the patch to link_to_remote in prototype_helper.rb

03/29/07 03:30:52 changed by chuyeow

  • summary changed from DRY up link_to_remote for degradable URLs to [PATCH] DRY up link_to_remote for degradable URLs.

05/19/07 04:40:29 changed by josh

It would be nice not to change the href on link_to_remotes with custom methods.

link_to_remote "Delete", :url => @post, :method => :delete

I don't want to link to /post/1.