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

Ticket #1269 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

[XPATCH] link_to_post helper

Reported by: nzkoz Assigned to: David
Priority: normal Milestone: 1.1
Component: ActiveRecord Version: 0.12.1
Severity: normal Keywords:
Cc:

Description

As mentioned at Signal vs Noise there are some problems with the use of GET.

We should have a helper to make this easier.

Attachments

link_to_post.diff (3.1 kB) - added by nzkoz on 05/06/05 20:57:47.
The patch to implement as mentioned

Change History

05/06/05 16:38:52 changed by nzkoz

One implementation would be

<form action="#{the_url}" method="post">
  link_to_function("#{link_text}", "this.parentNode.submit();return false")
</form>

05/06/05 20:57:47 changed by nzkoz

  • attachment link_to_post.diff added.

The patch to implement as mentioned

05/06/05 20:58:17 changed by nzkoz

  • summary changed from link_to_post helper to [PATCH] link_to_post helper.

05/07/05 01:14:08 changed by lee@omara.ca

How about a complimentary post_button method that used a submit button for situations where being javascript-free is more important than using text links?

def post_button(name, options={}, html_options = {})
  s = form_tag(options)
  s << submit_tag(name, html_options)
  s << "</form>"
  return s
end

The main problem I see with both of these approaches is that they depend on creating a new form, which could cause issues with any form that spans multiple records (since you can't nest forms)

05/07/05 16:06:59 changed by nzkoz

post_button sounds like a nice idea, I think it should probably be in a seperate patch though.

As for the 'nested form' problem, it's definitely an issue, but I can't see an easy way around this?

05/09/05 15:58:09 changed by nzkoz

  • summary changed from [PATCH] link_to_post helper to [XPATCH] link_to_post helper.

this patch should incorporate both a post_button and a link_to_post.

Additionally, the test cases should test the :confirm behaviour etc.

05/09/05 20:16:47 changed by tom@moertel.com

I really like the ideas on this page. May I offer a few comments?

Regarding the post_button method, please consider two suggestions. First, the submit tag cannot appear directly within the form element and still be legal XHTML. An intermediary div element will take care of the problem. (Other elements will also suffice, but divs carry less stylistic baggage.) Second, can we more closely mirror the semantics of link_to? Right now, the handling of the parameters is subtly different.

Please feel free to use or borrow from button_to, which incorporates both suggestions. I provide the code for it in this post: Taking the unsafe GETs out of Rails.

Regarding the link_to_post method, it also suffers from not generating legal XHTML. Placing a div around the a element will also fix this problem.

On an accessibility note, do we want to encourage solutions that fail without scripting support? (For background, see Section 6 of the WAI's Web Content Accessibility Guidelines 1.0.) Can we not promote a solution more like that proposed by Aristotle Pagaltzis in I don’t GET the problem, which uses scripting to improve reactivity without requiring it?

Cheers,
Tom

12/08/05 05:40:22 changed by bitsweat

  • milestone changed from 1.0 to 1.1.

Is this still relevant?

07/07/06 23:15:47 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.