2012-09-15 4 views
1

POST 요청을 리디렉션하려고하면 레일의 플래시 해시가 지워집니다.ruby-on-rails에서 POST 요청을 리디렉션하면 플래시 해시가 지워집니다.

리디렉션은 초기 요청이 GET 인 경우 잘 작동합니다.

설정에서

/routes.rb

응용 프로그램/컨트롤러/test_controller.rb에서
post 'test/hello' 
#get 'test/hello' #uncomment this line and comment out the post and the flash is preserved 
get 'test/goodbye' 

응용 프로그램에서
def hello 
    respond_to do |format| 
     format.html do 
      redirect_to movies_goodbye_url, :notice => "I disappear on post requests" 
     end 
    end 
end 

def goodbye 
end 

/보기/테스트/goodbye.html.haml

%h1 Test#goodbye 
%p#alert= alert 
%p#notice= notice 

이 작업을 통해 오류 사례에서 내 기존보기 중 하나로 리디렉션되는 양식 제출의 게시물을 처리 할 수 ​​있습니다. 레일스에 익숙하지 않기 때문에이 유스 케이스를 처리 할 수있는 더 좋은 방법이 있다면 알려 주시기 바랍니다.

답변

2

시도가에 flash.keep를 추가 : 또한

flash.keep(:notice) 
redirect_to movies_goodbye_url, :notice => "I disappear on post requests" 

참조 : Flash message in redirect not working

+0

한 멋진 캐치! 레일스는 왜 이런 식으로 작동합니까 ??? 버그 추적기에 버그로 제출해야합니까? –

관련 문제