路由對我來說總是令人討厭的事情之一。耙路線會顯示我可以使用的信息,但我無法按照我希望的方式操作信息。在我的程序中,我有一個用戶模型,爲此我使用了設計。每個用戶都可以創建員工,員工成爲他們自己的用戶(使用登錄憑證等)。獲取'Rake Routes'來顯示我想要的信息
我遇到了員工「更新」方法的問題。用戶更新方法正常工作。當我運行耙路線,我得到以下行
PUT /users(.:format) devise/registrations#update
PUT /employees/:id(.:format) employees#update
當我嘗試更新我的員工,我得到的錯誤
No route matches [PUT] "/employees"
這就是我希望能夠向他提出的路線,但它看起來像鐵軌寧願給我/員工/:id來處理。
我的路線文件包括
devise_for :users
resources :users, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
resources :employees, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
任何幫助將是巨大的,並且在操控着我的路線的任何其他信息將是燦爛的。謝謝!
編輯
這裏是我的更新員工的控制器方法
def update
@employee = current_company.users.find(params[:id])
if @employee.update_attributes(params[:employee])
redirect_to :action => 'show', :id => @employee.id
flash[:notice] = "Employee information updated"
else
render :action => 'edit'
flash[:notice] = "No edits were made"
end
end
我添加了我的更新方法的帖子。這是否會告訴需要更新的員工?我認爲它確實如此。我對嗎? – Mike
是的,這會更新員工。但是你在那裏使用'params [:id]',所以你應該對'/ employees /:id'執行一個put請求,而不是'/ employees'。 – Mischa