0

我試圖重定向用戶show_city_urlshow_city_path但我得到一個異常,他們都是undefined。在城市控制器我有三個動作顯示,喜歡和不喜歡。 unlike_city_pathlike_city_path作品,但show_city_path doesnt.Also當我把這個在all_cities行動redirect_to :controller=>"city",:action=>"show"作品。我做錯了什麼?謝謝。足智多謀的助手_path和_url不工作

class HomeController < ApplicationController 

    def all-cities 
     redirect_to show_city_url 
    end 

    end 

在路線

 resources :city do 
    member do 
    post :like 
    post :dislike 
    get :show 
    end 
    end 

回答

1

根據您的意見:

resources :cities, :controller => 'city' do 
    collection do 
    get :show, :as => :show 
    end 

    member do 
    post :like 
    post :dislike 
    end 
end 

現在你可以打電話show_cities_url,你會在你的CityController的表演動作着陸。

PS:繼Rails的慣例,使您的生活更輕鬆;)

回報率指南:Rails Routing from the Outside In

+0

現在它告訴我未初始化的常量CitiesController – katie

+0

什麼是你的控制器的顯示/列出了城市的名字嗎? – sled

+0

它是CityController – katie

相關問題