2016-07-14 47 views
0

我正在寫一個小Rails CMS,我有點卡路由錯誤。首先,我有一個名爲Entry的基本模型,其他模型正在繼承。當我嘗試編輯現有的模型,它返回我一個錯誤編輯方法中的路由錯誤

No route matches [PATCH] "/admin/posts/entries" 

在我的CMS routes.rb插件我有以下幾點:

Multiflora::Engine.routes.draw do 
    root "dashboard#index" 

    scope "/:content_class" do 
    resources :entries 
    end 
end 

和測試應用程序的routes.rb

mount Multiflora::Engine, at: '/admin' 

application_controller.rb我也調整了一下路線:

def content_entries_path 
    entries_path(content_class: content_class.tableize) 
end 
helper_method :content_entries_path 

def content_entry_path(entry) 
    entry_path(entry, content_class: content_class.tableize) 
end 
helper_method :content_entry_path 

def new_content_entry_path 
    new_entry_path(content_class: content_class.tableize) 
end 
helper_method :new_content_entry_path 

def edit_content_entry_path(entry) 
    edit_entry_path(entry, content_class: content_class.tableize) 
end 
helper_method :edit_content_entry_path 

在我show.html.erb我有這樣的:

<%= link_to 'Edit', edit_content_entry_path(@entry) %> 

當我瀏覽到edit_content_entry_path,它顯示我的編輯頁面正確的,但是當我嘗試保存編輯的條目,則返回我上述錯誤。當我運行rake routes,它返回我下面的:

entries GET /:content_class/entries(.:format)   multiflora/entries#index 
     POST /:content_class/entries(.:format)   multiflora/entries#create 
new_entry GET /:content_class/entries/new(.:format)  multiflora/entries#new 
edit_entry GET /:content_class/entries/:id/edit(.:format) multiflora/entries#edit 
entry GET /:content_class/entries/:id(.:format)  multiflora/entries#show 
     PATCH /:content_class/entries/:id(.:format)  multiflora/entries#update 
     PUT /:content_class/entries/:id(.:format)  multiflora/entries#update 
     DELETE /:content_class/entries/:id(.:format)  multiflora/entries#destroy 

回答

0

因此,錯誤在我edit.html.erb觀點 - 而不是

<%= form_for(@entry, as: :entry, url: content_entry_path(@entry)) do |f| %> 

<%= form_for(@entry, as: :entry, url: entries_path do |f| %> 

當我重寫它,一切正常!