我想在Mercury编辑器中使用保存功能,但无济于事。
我有一个模型来保存页面,标题和内容。
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>
答案 0 :(得分:1)
好的,所以我基本上意识到我需要一个show动作,所以我可以从模型中获取记录并保存到@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类,并将所有代码移动到show.html.erb,不需要about.html.erb。