0

Railscastチュートリアルに従って、mercury エディターをセットアップしました。

mercuy.js

$(window).bind('mercury:ready', function() {
  var link = $('#mercury_iframe').contents().find('#edit_link');
  Mercury.saveUrl = link.data('save_url');
  link.hide();
});

$(window).bind('mercury:saved', function() {
  window.location = window.location.href.replace(/\/editor\//i, '/');
});

ビュー/引用/show.html.erb

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

水銀.html.erb

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

ルート.rb

  resources :quotations  do
    member { post :mercury_update}
  end

次のエラーが表示されます

Mercury was unable to save to the url: http://localhost:3000/quotations/1

コンソール出力

Started PUT "/quotations/1" for 127.0.0.1 at 2015-03-07 19:20:49 +0530

AbstractController::ActionNotFound (The action 'update' could not be found for QuotationsController):

静的IDではうまく機能しましたが、これは好きではありませんでした。このエラーを解決するのを手伝ってください。

4

1 に答える 1

0

あなたのエラーはあなたに言っています

ActionNotFound 

つまり、QuotationsController に Mercury_update がありません。追加してみる

def mercury_update
  quote = Quotations.find(params[:id])
  quote.FIELD_FROM_YOUR_DB = params[:content][:quotation_content][:value]
  quote.save!
  render text:""#tells mercury of successful save (I think)
end

それでもうまくいかない場合は、水銀が通過しているパラメーターをコンソールで確認してください。次のように見えるはずです

Started PUT "/quotations/1/mercury_update" for ...
  Parameters:{"content"=>{...}}

これは PUT リクエストであることに注意してください。これが、Mercury が実行していることを示していることです。したがって、ルートを更新する必要があります

resources :quotations do
  member do
    put 'mercury_update' #this may change your path to mercury_update_quotation_page_path(@quotation)
  end
end

また、config/routes.rb で resources :quotations が 2 回定義されていないことを確認してください。そのチュートリアルに従って定義し、実行しました

rails g scaffold quotations

ビューなどを自動生成するため。このコマンドは、config/routes.rb の上部に引用符を再度定義しました。

resources :quotations
#...
resources :quotations do #... This was my definition

したがって、メンバー「mercury_update」を使用した私の定義は無視されます。

最後に、保存された応答が機能しているかどうかをお知らせください。私のものはそうではありません。GL!

于 2015-09-04T02:22:25.430 に答える