index
및 show
두 가지 동작이 정의 된 레일 컨트롤러가 있습니다. index
액션에 인스턴스 변수가 정의되어 있습니다.컨트롤러의 모든 동작에 대해 동일한 인스턴스 변수
def index
@some_instance_variable = foo
end
def show
# some code
end
가 어떻게이 @some_instance_variable
show.html.erb
템플릿에 액세스 할 수 있습니다 : 코드는 무엇인가 아래처럼?
Thanks @Emily. 그러나 이것을하기위한 건조한 방법이 있습니까? – Red
감사합니다. @Emily 나는 똑같은 것을 찾고있었습니다. 건배! – Aashish
'before_action : set_up_instance_variable, only : [: show, : index]'를 컨트롤러에 추가하십시오. 그것은 당신이 지정하는 동작 전에'set_up_instance_variable'을 실행합니다. – domi91c