@current_day와 @has_day를 내보기에 전달하는 방법을 궁금해하고 있었습니까?howto가 before_filter에서보기를 위해 vars를 전달합니다.
class PostController < ApplicationController
before_filter :detect_current_day
def index
#some logic
end
private
def detect_current_day
if (params[:year] && params[:month] && params[:day])
@current_day = Date.parse params.values_at(:year, :month, :day).join('.')
else
@current_day = Date.today;
end
# Check if day already exist
@hasToday = Post.created_on(@current_day).count > 0 ? true : false;
end
end
감사
인스턴스 변수를 설정하면 충분합니다. 그 이상이면 안됩니다. 너의 잘못은 뭐니? – apneadiving
어딘가에 오타가 있음에 유의하십시오. 귀하의 질문에'@ has_day'가 언급되어 있지만 코드에는'@ hasToday'가 표시됩니다. – mbreining