I want to get the save function in the Mercury editor working but to no avail.
I have a model to save the page, title and content.
mercury.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, '/');
});
static_pages_controller.rb:
def update
@static_page = StaticPage.find(params[:id])
@static_page.page = params[:page]
@static_page.title = params[:content][:aboutContainer][:value][:about_title][:value]
@static_page.content = params[:content][:aboutContainer][:value][:about_content][:value]
@static_page.save!
render plain: ''
end
about.html.erb:
<% provide(:title, 'About') %>
<div class="container" id="aboutContainer" data-mercury="full">
<h1 id="about_title"><%= raw @static_page.title %></h1>
<div class="col-sm-12">
<p id="description about_content"><%= raw @static_page.content %></p>
</div>
<p><%= link_to "Edit Page", "/editor" + request.path, id: "edit_link",
data: {save_url: static_page_update_path(@static_page)} %></p>
</div>
Ok, so i basically realised that I needed a show action so I can grab records from the model and save to the @static_page object
I was following this guide: http://railscasts.com/episodes/296-mercury-editor?autoplay=true
Please note I had to change my routes to using those in the link (or similar routes to them) and had to place them before the default mercury routes and had to change:
@static_page.title = params[:content][:aboutContainer][:value][:about_title][:value]
@static_page.content = params[:content][:aboutContainer][:value][:about_content][:value]
to:
@static_page.title = params[:content][:about_title][:value]
@static_page.content = params[:content][:about_content][:value]
I then removed the class 'container' div in about.html.erb and moved all the code to show.html.erb not needing about.html.erb.
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.