我有一個名爲員工的控制器。導軌路由和活動記錄錯誤
class EmployeesController < ApplicationController
def admission
@bank_fields = BankField.all.where(:status => true)
if @bank_fields.empty?
redirect_to :action => "show", :id => @bank_fields.first.id
end
end
def show
@employee = Employee.find(params[:id])
end
# The RESTful actions are as usual; I didn't give those here.
end
在路線
文件
match ':controller/:action/:id', :via => [:get, :post,:put]
match ':controller/:action', :via => [:post, :get]
resources :employees
在我所謂的入院行動鑑於
<%= link_to 'admission', :controller => :employees, :action => :admission %>
但是當我按下鏈接我得到了下面的錯誤。
ActiveRecord::RecordNotFound at /employees/admisson
Couldn't find Employee with id=admisson
這意味着其擊球的演出action.Which我不知道why.Is有任何solution.Thanks
你缺少的:ID在你的link_to.You應傳遞一個:ID。 – Pavan
感謝您的答覆。我實際上不需要id。我想重定向到 匹配':controller /:action',:via => [:post,:get] 這條路徑。指向 匹配':controller /:action /:id',:via => [:post,:get] 我不想這樣做。 – user3316484
目前你有bankfields的記錄status => true? – Pavan