2016-08-18 140 views
0

(Rails 4.2) 我有route.rb文件中的路由與從我的頁面生成的路由錯過了匹配。我做錯了什麼? 這是前傾的路線我想訪問:生成的路徑與自定義路由不符?

see_hint_deck_card_tracker GET /decks/:deck_id/cards/:card_id/trackers/:id/see_hint(.:format) trackers#see_hint 

其實我帶到什麼,我認爲是正確的URL,但它告訴我,我不具有該頁面的路線:

http://localhost:3000/decks/9/cards/2/trackers/1/see_hint 

我有以下路線:

resources :decks do 
    resources :cards do 
     resources :trackers do 
     member do 
      get 'see_hint' 
     end 
     end 
    end 
    end 

應用程序/控制器/ tracker_controller.rb:

class TrackerController < ApplicationController 
    def show_hint 
     puts 'we found this' 
    end 
end 

在我的/甲板/:ID /卡/:ID /節目我有這樣的link_to:(get_tracker,要求一個輔助方法以獲得正確的跟蹤器)

<%= link_to "Reveal Hint", see_hint_deck_card_tracker_path(@card.deck, @card, get_tracker), id: "reveal_hint_button" %> 

回答

2

我覺得你的錯誤信息可能告訴你,你沒有該路線的控制器,而不是路線丟失。這是因爲你在你的routes.rb使用複數resources,但你的控制器名稱爲單數:

# Your Code: 
resources :trackers 
controller TrackerController 

# Expected Code: 
resources :trackers 
controller TrackersController 
       ^^^ 

你還需要確保你的控制器可在app/controllers/trackers_controller.rb(注意是多個)。

+0

拍攝。重做控制器,使語法匹配! – Michael

+0

銷燬控制器,而不是以複數形式重新生成。作品! – Michael