0

对于我的 Rails 应用程序,我有一个表单,可以在提交时在模型中保存“内容”。如何修改下面的脚本并使用“会话”以便“onSuccess(事件)”,我将警报的内容分配为临时值,:content并且我的页面使用 text_area 内的警报内容重新加载/刷新?

<%= form_for([@project, @project.blogs.build]) do |f| %>
  <div class="field">
    <%= f.text_area :content, label: "Blog", :class => "redactor" %>
  </div>
  <%= f.submit "Submit" %>
<% end %>

<script>

    ...

    function onSuccess(event) {
      alert('NICE! ' + event.data.Id + ' was added.');
    }

    ...

</script>
4

2 回答 2

0

如果你使用 redactor.js。

function onSuccess(event) {
  $('.redactor').redactor('insertText', 'NICE! ' + event.data.Id + ' was added.');
}
于 2013-07-13T05:23:49.257 回答
0

ajax 有一个选项

<%= form_for [@project, @project.blogs.build], :remote => true, :html => { :id => "ajax_form" } do |f| %>
  <div class="field">
    <%= f.text_area :content, label: "Blog", :class => "redactor", :id => "change_me" %>
  </div>
  <%= f.submit "Submit" %>
<% end %>

<script>

    $(function() {
      $("#ajax_form").bind('ajax:success', function(data, status, xhr) {
         $("#change_me").val("changed");
      }).bind('ajax:error', function(xhr, status, error) {
        console.log(error);
        console.log(status);
      });
    });

</script>
于 2013-07-13T02:30:51.993 回答