현재 Rails 4.2를 사용하고 있습니다.
lib 디렉토리 아래에 모듈을 만들었습니다. 에서 유지 관리 메서드를 호출하고 app/controllers/applicaiont_controller.rb
싶지만 실패했습니다.
NoMethodError in ProductsController#index
undefined method `redirect_to` for #<...>
내 lib의 모듈은 다음과 같습니다.
module One
class Display
response = other_method
if response.status == 200
data = 'OK'
else
redirect_to_maintencance 'Maintenance ...'
end
data
end
end
app / controllers / applicaiont_controller.rb
class ApplicationController < ActionController::Base
# Other methods
def redirect_to_maintencance(message = nil)
redirect_to :maintencance, flash: { maintencance_message: message }
end
end
lib 모듈에서 리디렉션 방법을 사용하는 것은 좋은 방법이 아닙니다. 상태 확인 로직을 컨트롤러 또는 도우미로 이동합니다.
@ jphager2 덕분입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다