0
嗨有以下設置CanCan Current_Client錯誤
我有一個登錄系統,客戶端登錄到系統。他們可以編輯系統上的細節。我需要阻止他們編輯其他客戶端的細節。這可以通過更改URL中的ID來完成。
有一個地方一個命名空間,它被稱爲「個人資料」
我已經在系統上有用戶這樣做之前,是否慘慘只支持CURRENT_USER或我可以改變這current_client。
NameError(未定義局部變量或方法`CURRENT_USER」的#):如我在以下的日誌文件中獲取的誤差
代碼如下:
應用控制器
protect_from_forgery
helper_method :current_client
rescue_from CanCan::AccessDenied do |exception|
redirect_to profile_url
end
private
def current_client
@current_client ||= Client.find(session[:client_id]) if session[:client_id]
end
def logged_in?
unless session[:client_id]
flash[:notice] = "You need to log in first."
redirect_to login_path
return false
else
return true
end
end
資料/ clients_controller
before_filter :logged_in?
load_and_authorize_resource
# GET /clients/1/edit
def edit
@client = Client.find(params[:id])
end
# PUT /clients/1
# PUT /clients/1.json
def update
@client = Client.find(params[:id])
respond_to do |format|
if @client.update_attributes(params[:client])
format.html { redirect_to [:profile,@client], :notice => 'Client was successfully updated.' }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @client.errors, :status => :unprocessable_entity }
end
end
end
任何I dea爲什麼它會提出這個錯誤。