2015-02-04 3 views
-1

다른 사용자가 만든 리소스를 표시하지만 current_user가 만든 리소스를 숨기는 페이지를 만들고 싶습니다. 내가 할 수있는 방법이나 방법이 있습니까?자원을 숨기려면 어떻게해야합니까?

class ExamplesController < ApplicationController 
    def index 
    @examples = Example.all.order("created_at DESC") 
    @creator_examples = Example.where(creator: current_user).order("created_at DESC") <---hide this!!! 
    end 

답변

1

당신은 단순히이 같은으로 where 절을 조작 할 수 있습니다 :

def index 
    @examples = Example.all.order("created_at DESC") 
    @creator_examples = @examples.where.not(id: current_user.id) 
end 

이, 레일 4 당신이 레일 3

@creator_examples = Example.where("id != ?", current_user.id) 

를 사용하는 경우 - > 레일 3의 Example.all은 배열을 반환하므로 체인을 연결할 수 없습니다. where

관련 문제