0

こんにちは、次の設定があります

クライアントがシステムにログインするためのログインシステムがあります。システム上で詳細を編集できます。彼らが他のクライアントの詳細を編集するのをブロックする必要があります。これは、URL の Id を変更することで実行できます。

名前空間が配置されており、「プロファイル」と呼ばれます

システム上のユーザーでこれを行ったことがあります。CanCan は 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

このエラーが発生する理由。

4

1 に答える 1

0

以下を利用しました:

  helper_method :current_user

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to profile_url
  end

  private

  def current_user
    @current_user ||= Client.find(session[:client_id]) if session[:client_id]
  end
于 2012-10-18T09:16:28.750 に答える