2014-09-23 39 views
0

我正在寫什麼是目前非常不雅的程序來生成健身計劃,並有路由問題。我希望我的索引頁面上的按鈕鏈接到特定的正文部分和計劃生成器,並且當我直接導航到它們時,這些頁面本身正在工作。但是,我的索引視圖中的按鈕不起作用,踢出路由錯誤:'沒有路由匹配[POST]「/ Exercises/index」'。Rails路由問題 - URL的作品,雖然按鈕鏈接到它不會

例如,下降的URL「/運動/腿」或「/運動/發電機」到我的瀏覽器加載所應當的頁面,雖然<%= button_to「腿」,「練習/腿」% >(以及重定向到Exercises_legs_path和我想過的每一個其他選項)會給出錯誤。

確定這是我錯過的很簡單的東西(對此很新),任何建議都會很棒!

該數據庫當前包含:id,':move'(即按下)和':bodypart'(即腿部)的列。

這裏是我的路線:

Helper      HTTP Verb Path       Controller#Action 
          GET  /exercises/:bodypart(.:format) exercises#bodypart 
exercises_generator_path GET  /exercises/generator(.:format) exercises#generator 
exercises_index_path  GET  /exercises/index(.:format)  exercises#index 
root_path     GET  /        exercises#index 
exercises_path    GET  /exercises(.:format)    exercises#index 
          POST  /exercises(.:format)    exercises#create 
new_exercise_path   GET  /exercises/new(.:format)   exercises#new 
edit_exercise_path   GET  /exercises/:id/edit(.:format) exercises#edit 
exercise_path    GET  /exercises/:id(.:format)   exercises#show 
          PATCH  /exercises/:id(.:format)   exercises#update 
          PUT  /exercises/:id(.:format)   exercises#update 
          DELETE  /exercises/:id(.:format)   exercises#destroy 

而且我的routes.rb文件:提前

Rails.application.routes.draw do 

    get '/exercises/:bodypart', to: 'exercises#bodypart' 
    get '/exercises/generator', to: 'exercises#generator' 
    get 'exercises/index' 

    root :to => 'exercises#index' 
    resources :exercises 

end 

感謝,讓我知道如果有什麼事我已經得到了將與幫助這個。

回答

0
Rails.application.routes.draw do 

    get '/exercises/:bodypart', to: 'exercises#bodypart', as: 'exercises_bodypart' 
    get '/exercises/generator', to: 'exercises#generator' 
    get 'exercises/index' 

    root :to => 'exercises#index' 
    resources :exercises 

end 

代替

Rails.application.routes.draw do 

    get '/exercises/:bodypart', to: 'exercises#bodypart' 
    get '/exercises/generator', to: 'exercises#generator' 
    get 'exercises/index' 

    root :to => 'exercises#index' 
    resources :exercises 

end 

用法:

exercises_bodypart_path('legs') 
+0

謝謝@Ahmet KAPIKIRAN。完成,但奇怪的是它給我測試過的鏈接提供了三個不同的錯誤。我測試了三個身體部位,'完整','肩膀'和'腿',並分別得到以下錯誤:完整的「練習/全路由錯誤 沒有路線匹配[POST]」/ Exercises/full「」 (因爲我最初是爲他們所有人),肩膀「練習/索引,路由錯誤 沒有路線匹配[POST]」/ Exercises/index「」和腿:「/ ExercisesController#中的NoMethodError#創建 undefined方法'許可'爲零:NilClass「....任何想法? – SRack 2014-09-23 11:57:32