【问题标题】:Mercury editor cannot save changes [closed]Mercury 编辑器无法保存更改 [关闭]
【发布时间】:2012-09-17 09:46:52
【问题描述】:

我在我的 Rails 应用程序(https://github.com/jejacks0n/mercury.git,8fd7f73029)中使用 Mercury 所见即所得编辑器,但我无法处理它来保存文章更改,并出现错误“Mercury 无法保存到 url”。谷歌控制台给出以下日志:

ailed to load resource: the server responded with a status of 404 (Not Found)    http://localhost:3000/articles/3/mercury_update
Failed to load resource: the server responded with a status of 404 (Not Found)    http://localhost:3000/articles/3/mercury_update
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/articles/3/mercury_update
PUT http://localhost:3000/articles/3/mercury_update 404 (Not Found) jquery-1.7.js:8158

routes.rb

mount Mercury::Engine => '/'
resources :articles do
 member { post :mercury_update }
end

mercury.js 代码插入在 debug:false 之后,

onload: function() {
  //Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
  Mercury.on('ready', function() {
    var link = $('#mercury_iframe').contents().find('#edit_link');
    Mercury.saveUrl = link.data('save-url');
    link.hide();
  });

  Mercury.on('saved', function() {
    window.location.href = window.location.href.replace(/\/editor\//i, '/');
  });
 },

show.html.erb

<span data-mercury="full" id="page_title"><%= raw @article.title %></span>
<div data-mercury="full" id="page_body"><%= raw @article.body %></div>

<%= link_to "Edit",  "/editor" + request.path, id: "edit_link", data: {save_url:   mercury_update_article_path(@article)} %>

articles_controller.rb

def mercury_update
  article = Article.find(params[:id])
  article.title = params[:content][:page_title][:value]
  article.body = params[:content][:page_body][:value]
  article.save!
  render text: ""
end

在布局文件mercury.html.erb我有

<script type="text/javascript">
  // Set to the url that you want to save any given page to, leave null for default    handling.
  var saveUrl = null;

  // Instantiate the PageEditor
  new Mercury.PageEditor(saveUrl, {
    saveStyle:  'form', // 'form', or 'json' (default json)
    saveMethod: null, // 'PUT', or 'POST', (create, vs. update -- default PUT)
    visible:    true  // boolean - if the interface should start visible or not
  });
</script>

我尝试了所有方法,但没有任何效果

【问题讨论】:

    标签: ruby-on-rails-3 editor wysiwyg mercury-editor


    【解决方案1】:

    简单的错字 - 在布局中我有条件渲染 div id="page_title" 所以有两个标签,在第二种情况下忘记包含 id="page_title"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      相关资源
      最近更新 更多