用戶的URL在我的應用程序RecordNotFound如下:的ActiveRecord ::手動更改URL
localhost:3000/users/1/dashboard
當有人手動在URL改變user ID
了一些不具有用戶asigned它給我的錯誤:
Couldn't find User with id=X.
有沒有辦法將用戶返回到別的地方?
我試着在user_controller.rb是這樣的:
@user = User.find(params[:id])
unless @user
redirect_to root_path
end
當你這樣做了什麼事?另外,我們可能需要查看更多包含該代碼的方法。 – dpassage