开发者

Rails submit_to_remote can't POST

I'm trying to nest a form within another using submit_to_remote but it does a PUT instead of a POST. Can anyone explain what's wrong here?

The routes are RESTful:

map.resources :thing
map.resources :item

The view is like this:

<% form_f开发者_JAVA百科or(@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 %>

To get around the problem I've been adding another method to the restful routes to do a create on a PUT but it's ugly and I want to know what the problem is.

The submit_to_remote comes out as:

<input name="create" onclick="new Ajax.Request('/items', {asynchronous:true, evalScripts:true, method:'post', parameters:Form.serialize(this.form) + '&amp;authenticity_token=' + encodeURIComponent('blah')});" type="button" value="Create">

Thanks


How about using link_to_remote instead and style the link to like a 'button', or just leave it as a link would be fine to be honest. This way you can control the XmlRequest fully. Currently I think the method is being determined by your actual form that is being submitted by the JS, not the :method your setting in the helper call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜