我正在將汞添加到簡單的博客應用程序中,並且希望使用最新版本,但我一直無法保存更新。這裏是我的代碼:Mercury編輯器(0.9.0)無法在Rails中保存更改3.2.11
的Gemfile:
gem 'rails', '3.2.11'
gem "thin", "~> 1.3.1"
gem 'mercury-rails'
gem 'paperclip'
group :development do
gem 'taps'
gem "nifty-generators"
gem 'sqlite3'
end
gem 'jquery-rails'
blogs_controller.rb:
def update
@blog = Blog.find(params[:id])
if @blog.update_attributes(params[:blog])
redirect_to @blog
else
render 'edit'
end
end
def mercury_update
blog = Blog.find(params[:id])
blog.content = params[:content][:blogContent][:value]
blog.save!
render text: ""
end
blog.rb:
class Blog < ActiveRecord::Base
attr_accessible :title, :content, :author
end
的routes.rb:
Mercury::Engine.routes
mount Mercury::Engine => '/'
root :to => "pages#home"
namespace :mercury do
resources :images
end
resources :blogs do
member { post :mercury_update }
end
mercury.html.erb
<body>
<script type="text/javascript">
// Set to the url that you want to save any given page to, leave null for default handling.
var saveUrl = null;
// Instantiate the PageEditor
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
});
</script>
</body>
博客/ show.html.erb:
<div id="blogFull" class="rounded-corners-mild">
<div id="blogTitle">
<h1 style="font-size:150%; text-align:center; " class="mercury-region" ><%= @blog.title%></h1>
</div>
<div data-mercury="full" id="blogContent" class="mercury-region">
<%= raw @blog.content %>
</div><br />
<%= link_to "mercury", "/editor" + "/blogs" + "/#{@blog.id}", :class => 'bestButton',
id: "edit_link", data: {save_url: mercury_update_blog_path(@blog)} %>
加入到:mercury.js:
jQuery(window).on('mercury:ready', function() {
var saveUrl = $("#edit_link").data("save-url");
Mercury.saveUrl = saveUrl;
});
Mercury.on('saved', function() {
window.location.href = window.location.href.replace(/\/editor\//i, '/');
});
我也試圖與這樣的: mercury.js:
onload: function() {
//Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
Mercury.on('ready', function() {
var link = $('#mercury_iframe').contents().find('#edit_link');
Mercury.saveUrl = link.data('save-url');
link.hide();
});
Mercury.on('saved', function() {
window.location.href = window.location.href.replace(/\/editor\//i, '/');
});
}
都沒有工作。兩人都讓我去看編輯,讓我編輯。我還沒有能夠保存任何更改。謝謝。
是的。現在,我將我的保存方法更改爲POST,我得到一個錯誤。 「RoutingError(沒有路由匹配[POST]」/ blogs/3「)」,但它顯然在路由文件中作爲Post路徑。任何想法如何解決它? – thatdankent
沒關係。我知道了。謝謝! – thatdankent
@thatdankent你能告訴我你是如何解決這個問題的嗎?乾杯。 – Ribena