如何在jQuery autosave提交中更改表单提交到的操作?(在轨道中)
我有一个评论模型,我希望人们能够保存草稿。它有一个布尔属性“draft”,允许保存注释(但尚未显示)。我正在为这些注释创建一个自动保存函数 当前注释表单的运行方式如下:控制器将变量@Comment初始化为@Comment=Comment.new。那么评论的形式是:如何在jQuery autosave提交中更改表单提交到的操作?(在轨道中),jquery,ruby-on-rails,ruby-on-rails-3,autosave,Jquery,Ruby On Rails,Ruby On Rails 3,Autosave,我有一个评论模型,我希望人们能够保存草稿。它有一个布尔属性“draft”,允许保存注释(但尚未显示)。我正在为这些注释创建一个自动保存函数 当前注释表单的运行方式如下:控制器将变量@Comment初始化为@Comment=Comment.new。那么评论的形式是: <%= form_for @comment, :remote => true do |f| %> <%= f.text_area :title, :class => "inputform"
<%= form_for @comment, :remote => true do |f| %>
<%= f.text_area :title, :class => "inputform" %>
<%= f.text_area :content, :class =>"inputform" %>
<%= f.submit "Submit", :class => "button" %>
<% end %>
然后引用create.js.erb文件:
<% post = user.posts.last %>
<% if post.draft == false %>
//code here deals with a true submission of a comment, to append tables etc.
<% else %>
//maybe some code here could alter the form on draft submission to make it update the same post next time?
<% end %>
//这里的代码处理注释的真实提交、附加表等。
//也许这里的一些代码可以修改提交草稿上的表单,以便下次更新同一篇文章?
所以我想知道,我希望提交的初稿能像它一样工作,并在评论表中创建一个条目。但是,我希望表单在随后的自动保存中更新该评论,并在提交评论供发布时将该评论保存为非草稿最终评论。在这些文件中有没有什么地方是我可以完成的
谢谢 在
create.js.erb
中:
$('#comment_form').attr('action', '<%= comment_path(@comment) %>');
$('#comment_form').append('<input name="_method" type="hidden" value="put" />');
所以只需在create.js.erb
中生成它:
$('#comment_form').attr('action', '<%= comment_path(@comment) %>');
$('#comment_form').append('<input name="_method" type="hidden" value="put" />');
$('comment#u form')。追加('');
这几乎可以工作,但在发送到本地主机时,它会运行一个无路由错误:ActionController::RoutingError(无路由匹配项)/posts/139)。我不知道它为什么这样做,对我来说它应该和你写的代码一起工作。有什么想法吗?
$('#comment_form').append('<input name="_method" type="hidden" value="put" />');