我的routes.rb
:
DigitalizmAdmin::Application.routes.draw do
## Admin routes
namespace :mercury do
resources :images
end
mount Mercury::Engine => '/'
devise_for :admins #, :skip => [:registrations, :passwords]
namespace :admin do
root :to => "admin#dashboard"
resources :categories do
member { post :mercury_update }
end
resources :posts do
member { post :mercury_update }
end
resources :pages do
member { post :mercury_update }
end
end
## Regular routes
root to: "welcome#index"
get 'posts/*categories_uri/:post_uri' => "posts#show"
get 'categories/*categories_uri' => "categories#show"
# here is the regular page route
get 'page/:uri' => "pages#show", as: :page
get 'sitemap/*categories_uri' => 'sitemap#show'
get 'sitemap' => 'sitemap#index'
## Catch all unexisted routes
match "*path", to: "application#render_404", via: :all
end
以下是我如何在视图中构建要编辑的链接:
= link_to "Edit", "/editor" + page_path(item)
在路线host/page/:slug
上,我可以看到该页面,但是当我在途中host/edit/page/:slug
时
我有404错误。
在浏览器控制台中我可以看到错误:
GET http://host/page/:slug?mercury_frame=true&_=1388132782182 404 (Not Found)
但所有水银编辑的js文件都已加载。
答案 0 :(得分:1)
尝试在视图中使用此代码
<%= link_to "Edit", "/editor" + admin_page_path(item), id: "edit_link", data: { save_url: mercury_update_admin_page_path(item) } %>
并将此代码放在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, '/');
});
}
然后导航至http://host/editor/admin/pages/:slug