2013-07-16 24 views
0

我有一個創建頁面模板的應用程序。用戶帳戶中有許多頁面(用戶模板)。我收到以下錯誤,當我點擊我的刪除按鈕:爲頁面控制器創建刪除路由

瀏覽器

Routing Error 

No route matches [DELETE] "/pages/1" 

HTML

<%= link_to 'Delete', page_path(page), :method => :delete, 
             :confirm => "Are you sure you want to delete?", 
             :remote => true, 
             class: 'btn btn-table-action btn-danger' %> 

控制器

def destroy 
    @page = Page.find(params[:attributeID]) 
    @page.destroy 

    render :index 
end 

路線

pages GET /pages(.:format)         pages#index 
      POST /pages(.:format)         pages#create 
edit_page GET /pages/:id/edit(.:format)      pages#edit 
    page GET /pages/:id(.:format)        pages#show 
      PUT /pages/:id(.:format)        pages#update 

UPDATE

的routes.rb

resources :pages, only: [:index, :show, :create, :edit, :update] do 
    resource :optin_integration, only: [:edit, :update] 
end 

我在哪裏開始創建一個刪除的方法,使我的刪除按鈕的功能Rails的?

+0

你可以發佈你的'config/routes.rb'文件嗎? – dasnixon

+0

我在routes.rb文件中包含':pages' – andy4thehuynh

+0

是的,然後做什麼@screenmutt建議並添加:摧毀''只有' – dasnixon

回答

1

你需要做出破壞現有的網頁資源。

resources :pages, only: [:index, :show, :create, :edit, :update, :destroy] do 
    resource :optin_integration, only: [:edit, :update] 
end 

這是一個不錯的tutorial on Rails routing

+0

謝謝@screenmutt。那個':摧毀'做了詭計。你搖滾 – andy4thehuynh

1

它看起來就像在你config/routes.rb文件,你需要添加

resources :pages 
相關問題