以前总是遇到一个问题,在需要AJAX,部分更新时link_to_remote太难看,想用button,所以只能用form_remote_tag,但是总是记不住格式,总要调试几次。那么,留个备份。
Rails 2.2 以后,就有button_to_remote了,方便很多
Rails 2.2 以后,就有button_to_remote了,方便很多
<% form_remote_tag :url => {
:controller => '/posts',
:update => 'update_div'
: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>