4

新しいアクションを作りたくて、それを「showemployees」と呼んでいます。それは私がすでにやったことです:

-> コントローラーで:

def showemployees
end

-> app/views/employees/showemployees.html.erb の作成

-> config/routes で

match "/employees/showemployees" => "employees#showemployees"

localhost:3000/employees/showemployees経由で showemployees.html.erb を開くにはこれで十分だと思いましたが、Rails は引き続き show アクション (リソース :employees から) をルーティングし、showemployees アクションを実行しないようです。教えてくれるから

ActiveRecord::RecordNotFound in EmployeesController#show
Couldn't find Employee with ID=showemployees

Rails が showemployees アクションを実行するには、何を変更する必要がありますか?


私のルートのソースコード:

System::Application.routes.draw do

  match "/employees/showemployees" => "employees#showemployees" #für showemployees.html.erb

  root :to => "employees#index"

  resources :course_to_dos

  resources :current_qualifications

  resources :expected_qualifications

  resources :skills

  resources :employees

  resources :positions

  resources :admin


end
4

2 に答える 2

5

Rails-wayを歩いてみてください。コレクションを取得したい場合は、コレクションを使用してください。

resources :employees do
  collection do
    get :showemployees
  end
end
于 2011-08-10T20:31:45.407 に答える
3

完全なルート ファイルを投稿すると、決定的な呼び出しを行うことができますが、エラー メッセージに基づいて、このルートの上に定義された employees#show へのより広範なルート定義マッピングが、一致するようになっているようです。

ルートは定義された順序で評価されるため、狭いルート パターンの上に非常に広いルート パターンが定義されている場合、狭いルートが呼び出されることはありません。

編集: ルートからスラッシュを取り除き、showemployees を実際の URL に追加して、

 match "employees/showemployees" => "employees#showemployees" 
于 2011-08-10T20:22:59.840 に答える