저는 여러 액션을 가진 컨트롤러를 가지고 있습니다 : URL의 속성으로 년과 월을 취합니다. 개인 메소드 check_date를 으로 만들었습니다. 날짜가 유효한지 확인하고 날짜가 미래가 아닌지 확인하십시오. redirect_to 후 컨트롤러 실행을 종료의 레일 방법은redirect_to를 사용한 후 컨트롤러 실행을 어떻게 중지합니까? (레일즈 사용)
def check_date(year, month)
if month < 1 || month > 12 || year < 2000
flash[:notice] = I18n.t 'archive.invalid_date'
redirect_to :action => 'index'
elsif year > Date.today.year || (year == Date.today.year && month > Date.today.month)
flash[:notice] = I18n.t 'archive.no_future'
redirect_to :action => 'month_index',
:year => Date.today.year,
:month => Date.today.month,
:type => params[:type]
end
end
있습니까?
나는 redirect_to 후 예외가 발생하거나 check_date에서 값을 반환하고 호출하는 각 작업에서이를 확인하는 중입니다 생각할 수있는 방법 -
def month_index
year = params[:year].to_i
month = params[:month].to_i
if !check_date(year, month)
return
...
end
같은 것을 그러나이 있는지 궁금해 이 일을하는 데 좋은 레일 방법. 내가 반을했다 그 redirect_to 레일을 호출하는 데 나는 중지 싶었지만, 그 일은 일어나지 않는 것으로 인식하고 싶습니다.
이것은 질문자의 문제를 해결할 수 있지만 여기 vrish88과 같은 해결책을 기대합니다. – iphone007