0

Rails アプリ ( https://github.com/jejacks0n/mercury.git 、 8fd7f73029 )で Mercury wysiwyg エディターを使用していますが、記事の変更を保存するためにそれを処理できません。 URL」。Google コンソールには次のログが表示されます。

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

ルート.rb

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

debug:falseの後にMercury.jsコードを挿入し、

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)} %>

article_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>

私はすべてを試しましたが、何もうまくいきません

4

1 に答える 1

0

単純なタイプミス - レイアウトでは、div id="page_title" の条件付きレンダリングがあったため、2 つのタグがあり、2 番目のケースに id="page_title" を含めるのを忘れていました

于 2012-09-17T19:13:07.000 に答える