Actually I ended up with two options to handle this (both should degrade
gracefully if I understand the :html option correctly).
Put all of the AJAX-y ness into the submit button.
<%= form_tag %>
<%= submit_to_remote(‘upload_list’, ‘Upload a List’,
:url => {:action => ‘target_list_upload_display’},
:html => {:action => ‘target_list_upload’, :class
=> ‘additem’}) %>
<%= end_form_tag %>
Make the form handle the AJAX call and then use a regular submit tag.
<%= form_remote_tag (:url => {:action => ‘target_list_upload_display’},
:html => {:action => ‘target_list_upload’})%>
<%= submit_tag(‘Upload a List’, :class => ‘additem’) %>
<%= end_form_tag %>
I think I’m going to go with #1 just because everything is encapsulated
in the submit.
In this case, I think the solutions are interchangeable. Can anyone
give me a good reason to favor one over the other?
It sounds you’ve gotten things under control, but for future references,
link_to_remote(“Submit”, {:method => :post, :url => {…}}). Actually, I
think it does a post by default.
Doug.
Doug,
You know, it’s funny - I had read the part of the link_to documentation
where it said that you could do a post. Sigh. This is much more
straightforward. I’ll give it a shot.
It sounds you’ve gotten things under control, but for future references,
link_to_remote(“Submit”, {:method => :post, :url => {…}}). Actually, I
think it does a post by default.
This is an AJAX call, and so the page isn’t refreshing. The border
always shows up around a button when you click it, but the page isn’t
being refreshed to restore the original link look and feel.
Luckily, I already have an RJS page to handle this :).
In order to avoid the irritating “image border after link clicked”
effect lingering, you have to effectively refresh the anchor display,
which you can do by refactoring just the anchor into a partial,
enclosing it in a div, and then doing a replace_html on the div. Like
so:
View:
<%= render(:partial => 'upload_link') %>
(_upload_link.rhtml has the anchor tag display inside of it)