0

私はプラグインを使用しておらず、代わりにチュートリアルhttp://ruby.railstutorial.org/chaptersを管理に使用しています。ただし、私が抱えている問題は次のとおりです

class UsersController < ApplicationController
  before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
  before_filter :correct_user,   only: [:edit, :update]
  before_filter :admin_user,     only: :destroy

私が望むのは、あなたが admin_user である場合、顧客を編集および更新できるようにすることです。しかし、 correct_user が使用されているため、機能しません

私は次のことを試しました

def correct_customer
    @customer = Customer.find(params[:id])
    redirect_to(root_path) unless current_customer?(@customer) || customer.admin?
end

しかし、その後、未定義の顧客がいます。管理者が選択した顧客を変更できるようにするための私の最善のアプローチは何でしょうか。

a customer#edit (not me) をクリックするとエラーが発生する

NameError in CustomersController#edit

undefined local variable or method `customer' for #<CustomersController:0xa51fd60>
Rails.root: /home/jean/rail/map
4

1 に答える 1

0

私はあなたが意味したと思います

redirect_to(root_path) unless current_customer?(@customer) || @customer.admin?
于 2012-08-13T17:08:29.113 に答える