I followed Railscast Tutorial to set up mercury editor.
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, '/');
});
views/quotations/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
It shows the following error
Mercury was unable to save to the url: http://localhost:3000/quotations/1
Console output
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):
It worked well for static id's but not like this. Please help me to solve this error.
Your error is telling you
ActionNotFound
Meaning you are missing the mercury_update in your QuotationsController. Try adding
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
If that doesn't work, try checking your console for the the parameters mercury is passing around. It should look something like
Started PUT "/quotations/1/mercury_update" for ...
Parameters:{"content"=>{...}}
Notice that it is a PUT request, that's what Mercury is telling you that it's doing. Thus the route needs to be updated
resources :quotations do
member do
put 'mercury_update' #this may change your path to mercury_update_quotation_page_path(@quotation)
end
end
Also, ensure that resources :quotations is not defined twice in config/routes.rb. I defined it following that tutorial and then ran
rails g scaffold quotations
in order to auto-generate views and such. This command defined quotations again at the top of my config/routes.rb as
resources :quotations
#...
resources :quotations do #... This was my definition
thus ignoring my definition with the member 'mercury_update'.
Finally, let me know if your saved response is working, as mine is not. GL!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.