0
我想獲取特定用戶的評論。我試圖打導軌路由不會按預期方式發送給控制器
var reviews_url = '/users/' + profile_id + '/reviews.json';
但在日誌中
Started GET "https://stackoverflow.com/users/23/reviews.json" for ::1 at 2015-05-03 10:50:01 -0700
Processing by ApplicationController#index as JSON
我能改,使這條路線打reviews#index
看到它沒有擊中reviews#index
?
routes.rb
resources :users do
resources :reviews
end
rake routes
GET /users/:user_id/reviews(.:format) reviews#index
編輯添加路由
get 'auth/:provider/callback', to: 'sessions#create'
root 'application#index'
get '*path' => 'application#index'
resources :users do
resources :reviews
resources :friendships
end
注:當我移動resources
上述get '*path' => 'application#index'
它按預期工作。不過,我希望每個電話都通過application#index
(該應用程序是一個知道當前用戶的SPA,基於application#index
中的用戶)。也許我應該命名空間這些路線到api
?
路線看起來正確......你的'ApplicationController'和'ReviewsController'看起來像什麼。你正在做認證或授權,可能會絆倒它? –
這真的很奇怪。你能發佈你的整個路線文件嗎?我能想到的唯一的事情就是在評論控制器中沒有定義索引操作。在您的應用程序控制器中是否有索引方法(看起來很奇怪)。 – jphager2
@ jphager2在這種情況下,它應該抱怨失蹤的行爲。 –