2014-12-20 4 views
-2

Добрый день,undefined метод `admin? ' для #

Я пытаюсь исправить, что у меня есть приложение для моих рельсов.

Heres прямое изображение вопроса:

http://oi62.tinypic.com/2z6v5w2.jpg

вот мой topic_policy.rb

class TopicPolicy < ApplicationPolicy 

def index? 
true 
end 

def create? 
user.present? && user.admin? 
end 

def update? 
create? 
end 
end 

Вот мой application_policy.rb

class ApplicationPolicy 
attr_reader :user, :record 

def initialize(user, record) 
@user = user 
@record = record 
end 

def index? 
false 
end 

def show? 
scope.where(:id => record.id).exists? 
end 

def create? 
user.present? 
end 

def new? 
create? 
end 

def update? 
user.present? && (record.user == user || user.admin?) 
end 

def edit? 
update? 
end 

def destroy? 
update? 
end 

def scope 
record.class 
end 

class Scope 
attr_reader :user, :scope 

def initialize(user, scope) 
@user = user 
@scope = scope 
end 

def resolve 
scope 
end 
end 
end 

И здесь themes_controller.rb

class TopicsController < ApplicationController 
def index 
@topics = Topic.all 
authorize @topics 
end 

def new 
@topic = Topic.new 
authorize @topic 
end 

def show 
@topic = Topic.find(params[:id]) 
authorize @topic 
end 

def edit 
@topic = Topic.find(params[:id]) 
authorize @topic 
end 

def create 
@topic = Topic.new(params.require(:topic).permit(:name, :description, :public)) 
authorize @topic 
if @topic.save 
redirect_to @topic, notice: "Topic was saved successfully." 
else 
flash[:error] = "Error creating topic. Please try again." 
render :new 
end 
end 

def update 
@topic = Topic.find(params[:id]) 
authorize @topic 
if @topic.update_attributes(params.require(:topic).permit(:name, :description, :public)) 
redirect_to @topic 
else 
flash[:error] = "Error saving topic. Please try again" 
render :edit 
end 
end 
end 

Я просто пытаюсь получить его для просмотра веб-страницы через приложение для рельсов, но я застрял.

+0

Пожалуйста, откорректируйте свой код правильно. Пожалуйста, уточните, где определена команда авторизации? Это из драгоценного камня? – nathanvda

+2

Код модели пользователя также будет полезен. – BroiSatse

+1

Где находится «администратор»? Метод определен. Это исходит от драгоценного камня? –

ответ

0

Мне удалось решить эту проблему, сделав метод администратора общедоступным, он был настроен как конфиденциальный.

Смежные вопросы