2012-08-13 117 views
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 

但後來我有一個未定義的客戶。如果管理員修改選定的客戶,允許用戶使用什麼是我的最佳方法。如果我點擊一個客戶#編輯(不是我)

NameError in CustomersController#edit 

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

回答

0

我想你的意思

redirect_to(root_path) unless current_customer?(@customer) || @customer.admin? 
+0

它做的作品,但是現在如果我改變自己的出現

錯誤普通用戶,我也有資格擁有管理員。爲什麼? – Jseb 2012-08-13 17:15:09