我正在嘗試爲Rails應用程序創建一系列靜態頁面。 「關於」頁面正常工作,但當我嘗試使用「條款」頁面的相同方法時,我得到一個未知的操作。我認爲這是與我的控制器。爲什麼我會收到「未知的行爲行爲'show'找不到」?
這是我的routes.rb文件:
resources :pages
get "pages/index"
match '/about' => 'pages#about'
match ':permalink', :controller => 'pages', :action => 'show', :as => 'about'
match '/terms' => 'pages#terms'
match ':permalink', :controller => 'pages', :action => 'show', :as => 'terms'
root :to => 'pages#index'
我的控制器看起來是這樣的:
class PagesController < ApplicationController
helper_method :search_performed?
def index
@search = Farm.search(params[:q])
@json = @search.result.to_gmaps4rails
end
protected
def search_performed?
params[:q].present?
end
def about
end
def feedback
end
def terms
end
end
任何想法是怎麼回事?
如果我只有路線:'match'/ about'=>'pages#about''和'match'/ show'=>'pages#show'' 則顯示'localhost:3000/about' about view,'localhost:3000/show'顯示show view。但是如果我在前兩條路由後添加路由:'match':permalink',:controller =>'pages',:action =>'show',:as =>'about'',那麼'localhost:3000/show'產生一個路由錯誤:'沒有路由匹配{:controller =>「pages」,:action =>「show」}'爲什麼?耙路由: about /about(.:format)pages#about show /show(.:format)pages#show about /:permalink(.:format)pages#show – 7stud
對於同一個動作,你有兩條路由: 'match'/ show'=>'pages#show'' and'match':permalink',:controller =>'pages',:action =>'show'' – zolter