我試圖在另一個表格中嵌套一個表格,使用submit_to_remote但它做了PUT而不是POST。任何人都可以解釋這裏有什麼問題?Rails的submit_to_remote不能POST POST
的路線是REST風格:
map.resources :thing
map.resources :item
的看法是這樣的:
<% form_for(@thing) do |f| %>
<% fields_for(Item.new) do |i| %>
<%= i.text_field :name %>
<%= submit_to_remote 'create', 'Create', :url => items_path, :method => "post" %>
<% end %>
<%= f.text_field :title %>
<%= f.submit 'Update' %>
<% end %>
爲了避開我已經加入其他方法到寧靜的路線做一個創造的問題一個PUT,但它很醜,我想知道問題是什麼。
的submit_to_remote出來爲:
<input name="create" onclick="new Ajax.Request('/items', {asynchronous:true, evalScripts:true, method:'post', parameters:Form.serialize(this.form) + '&authenticity_token=' + encodeURIComponent('blah')});" type="button" value="Create">
感謝
只是好奇你真的想用提交遠程表單來做什麼。 – Salil 2010-04-14 10:53:38
這是一個編輯窗體(物品),可以在主窗體中添加/編輯子項目(項目)。表單的流程很難分離表單,因此提交ajax。 – 2010-04-14 11:19:24