Monday, February 04, 2008

form_remote_tag with ajax and none ajax action

Does anyone else having the same problem as I do when trying to set the url for AJAX and none AJAX actions for the form_remote_tag? I always seem to forget how to do this. It always take me a couple of tries to get this right. Anyway, I am putting the correct way to do this here so I come back later when I forget.

<% form_remote_tag :url => {:controller => '/posts', :action => 'view'},
:html => {:action => {:controller => '/posts', :action => 'view', :id => @id}} do %>
<%= submit_tag 'View' -%>
<% end %>

<form action="/posts/view/1" method="post"
onsubmit="new Ajax.Request('/posts/view/1',
{asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
<input type="submit" value="View" />
</form>