我創建了一個新的控制器,並添加了一個新的動作(my_new_action)。對routes.rb我添加了此操作的路由,但是當我設置爲URL瀏覽器地址localhost:3000/users/my_new_action時,我將得到主題中的錯誤。Rails 3 - 找不到<controller>沒有ID
class UsersController < ApplicationController
# ....
def my_new_action
end
end
請問誰能幫助我,請問如何解決?
感謝
編輯
resources :users do
collection do
get 'my_new_action'
end
end
EDIT2 這是從終端的精確輸出:
Started GET "https://stackoverflow.com/users/my_new_action" for 127.0.0.1 at Sat Nov 26 13:55:50 +0100 2011
Processing by UsersController#my_new_action as HTML
filter_access_to tried to find User from params[:id] (nil), because attribute_check is enabled and @user isn't set, but failed: ActiveRecord::RecordNotFound: Couldn't find User without an ID
Completed 404 Not Found in 1ms
ActiveRecord::RecordNotFound (Couldn't find User without an ID):
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.8ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (6.0ms)
顯示'routes.rb' – Hauleth
我更新了我的問題。 – user984621
我懷疑這是你得到的確切的錯誤信息 - 你能發佈整個異常嗎? – deviousdodo