我想让水星编辑器中的保存功能工作,但没有效果。
我有一个模型来保存页面,标题和内容。
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: ''
endabout.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>发布于 2017-04-28 15:04:06
好的,我基本上意识到我需要一个表演动作,这样我就可以从模型中获取记录并保存到@static_page对象中。
我遵循这个指南:http://railscasts.com/episodes/296-mercury-editor?autoplay=true
请注意,我不得不将我的路线改为使用链接中的路线(或与其类似的路线),并且必须将它们放在默认的汞路线之前,并且必须更改:
@static_page.title = params[:content][:aboutContainer][:value][:about_title][:value]
@static_page.content = params[:content][:aboutContainer][:value][:about_content][:value]至:
@static_page.title = params[:content][:about_title][:value]
@static_page.content = params[:content][:about_content][:value]然后,我删除了about.html.erb中的类“容器”div,并将所有代码移到不需要about.html.erb的show.html.erb中。
https://stackoverflow.com/questions/43663123
复制相似问题