我按照Railscast教程设置了水星编辑器。
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>mercury.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
});routes.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运行得很好,但不是这样。请帮我解决这个错误。
发布于 2015-09-04 10:22:25
你的错误告诉你
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。我按照该教程定义了它,然后运行
rails g scaffold quotations以便自动生成视图等。此命令在我的config/routes.rb顶部再次定义引号为
resources :quotations
#...
resources :quotations do #... This was my definition因此忽略了我对成员'mercury_update‘的定义。
最后,让我知道你保存的回复是否起作用,就像我的不起作用。GL!
https://stackoverflow.com/questions/28915659
复制相似问题