[에러잡기] 레일스와 함께하는 애자일 웹 개발 in Rails 2.0.2
[8 장 태스크C : 장바구니 생성]에서 Rails 2.0.2를 사용하는 경우 발생하는 문제점에 대한 정리와 해결책 입니다.
발생 경위
/config/environment.rb file 42 line <책 132p>
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')
config.action_controller.session_store = :active_record_store
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')
config.action_controller.session_store = :active_record_store
데이터베이스에서 세션 두기 항목에서 세션정보의 저장소를 데이터 베이스로 지정하는 과정에서
위의 빨간부분만 주석처리를 제거할 것을 지시하고 있습니다. 책을 따라갈 경우 아래와 같은 에러 메세지를 만날 수 있습니다.
ActionController::InvalidAuthenticityToken
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).비밀이 위조로부터 보호라는 요청을 했다. 가 되나요? 여기서 secret은 비밀이 아니라 secret이라는 객체를 뜻하는 것 같습니다.
해결책
이 부분은 /config/enviroment.rb 에서 해결책을 찾을 수 없고, /app/controllers/application.rb 에서 답을 찾을 수 있습니다. 몇줄안 되는 소스인데 뒤져보면 secret에 관한 주석을 찾을 수 있습니다./app/controllers/application.rb file 7 line
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery :secret => '8c0e411f8a0da1fd5e01bd72a0c3f4b7'
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery :secret => '8c0e411f8a0da1fd5e01bd72a0c3f4b7'
─ tag :secret,
ActionController::InvalidAuthenticityToken,
Rails 2.0.2,
ROR,
Ruby,
secret given to the #protect_from_forgery call,
레일스와함께하는애자일웹개발


rss