所以我在使用我的rails應用程序時遇到了一些麻煩,我認爲我有點出於自己的深度。我正在創建一個簡單的校友應用程序,我希望用戶能夠加入組織。出於某種原因,在我的新加入頁面中,我收到錯誤「無法找到沒有ID的用戶」。我想知道爲什麼ID不通過,這意味着signed_in? =假。我不知道爲什麼一切工作都找到了,當我爲用戶控制器創建其他附加內容時,但在這裏拒絕接受登錄用戶標識。我覺得我缺少一些簡單的東西,讓我知道如果更新是必要的!「無法找到沒有ID的用戶」ActiveRecord錯誤和編輯故障
這裏是我的用戶控制器中的相關信息:我包括高清製作方法,因爲我想編輯它登錄之後將用戶重定向到聯接頁面,但那時,我發現這個錯誤就和
class UsersController < ApplicationController
before_action :signed_in_user, only: [:edit, :update, :index, :show, :join]
before_action :correct_user, only: [:edit, :update, :join]
before_action :admin_user, only: :destroy
def join
end
def show
@user = User.find(params[:id])
@organization = @user.organization
end
def create
@user = User.new(user_params)
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
...
private
def user_params
params.require(:user).permit(:name,:email, :password, :password_confirmation,:organization_id)
end
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
def admin_user
redirect_to(root_url) unless current_user.admin?
end
end
我認爲這是問題所以我把它切換回來。我想這不是....注意:如果這有幫助,我將基於Hartl教程的許多應用程序都基於此。
您的路線文件是什麼樣子的? – astephenb