3

Rails 2 앱을 Rails 3.2.13으로 업그레이드했는데 캐싱을 사용하려고 할 때 문제가 있습니다. 캐싱은 Rails 2에서 작동했으며 동일한 버전의 Ruby - 1.8.7을 사용하고 있습니다. 관련성이 있는지는 잘 모르겠지만 OSX에서 개발 중입니다.expire_fragment를 호출하면 #url_for를 사용하기 위해 명시 적으로 라우팅 도우미를 포함해야합니다. 오류

expire_fragment가 호출 될 때 ActionController :: Caching :: Fragments 클래스에서 오류가 발생합니다. expire_fragment을 포함하는 fragment_cache_key하는 호출을이 :

ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views) 

이 조금 더 확장 역 추적입니다

2013-07-10T14:40:50.430137+01:00 FATAL 
RuntimeError (In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers): 
lib/bio_catalogue/cache_helper.rb:175:in `expire_fragment' 
lib/bio_catalogue/cache_helper.rb:181:in `expire_service_index_tag_cloud' 
app/observers/annotation_observer.rb:33:in `expire_caches' 
app/observers/annotation_observer.rb:12:in `after_create' 
app/controllers/annotations_controller.rb:140:in `create_inline' 

이 오류를 제기한다 url_for하는이 호출 : 당연히

freya.2235 actionpack (3.2.13) lib/abstract_controller/url_for.rb:14:in `_routes' 
freya.2235 actionpack (3.2.13) lib/action_dispatch/routing/url_for.rb:148:in `url_= 
freya.2235 for' 
freya.2235 actionpack (3.2.13) lib/action_controller/caching/fragments.rb:53:in `f= 
freya.2235 ragment_cache_key' 
freya.2235 actionpack (3.2.13) lib/action_controller/caching/fragments.rb:112:in `= 
freya.2235 expire_fragment' 
freya.2235 lib/bio_catalogue/cache_helper.rb:175:in `expire_fragment' 
freya.2235 lib/bio_catalogue/cache_helper.rb:181:in `expire_service_index_tag_clou= 
freya.2235 d' 
freya.2235 app/observers/annotation_observer.rb:33:in `expire_caches' 
freya.2235 app/observers/annotation_observer.rb:12:in `after_create' 
freya.2235 activemodel (3.2.13) lib/active_model/observing.rb:231:in `send' 
freya.2235 activemodel (3.2.13) lib/active_model/observing.rb:231:in `update' 
freya.2235 activerecord (3.2.13) lib/active_record/observer.rb:114:in `_notify_ann= 
freya.2235 otation_observer_for_after_create' 

나는 expire_fragment를 호출하는 클래스에 Rails.application.routes.url_helpers를 포함하려고 시도했지만, ActionController 모듈 내에서 오류가 발생하면 아무 소용이 없습니다. ActionController :: Base에는 이미 UrlFor 모듈이 포함되어 있으므로 제 질문은 입니다. UrlFor를 포함하는 모듈의 클래스가 url_for를 잘 사용할 수 있어야 할 때 url_helpers를 포함하라는 오류를 발생시키는 이유는 무엇입니까?

+1

expire_fragment로 전송하기 전에 조각을 찾기 위해 url_for를 찾아 해결 방법을 찾았습니다. 예 : @ controller.expire_fragment (key, options) to @ controller.expire_fragment (Rails.application.routes.url_helpers.url_for (key.merge ({: only_path => true})) 옵션) – Njall

답변

0

또한이 오류가 발생했지만 내 통합 기능 테스트 및 단순한 link_to 도우미를 사용하는보기에서도 발생했습니다. 이 포스팅은 내 보석 종속성을 확인하는 경로를 나를 내려 보내 Routes stopped working when upgrading Rails 3.0 to 3.1

난에서 다음을 변경하여 문제를 해결할 수 있었다 :

group :development, :test do 
    gem 'mocha', '0.10.0', :require => false 
    gem 'vcr', '1.11.3' 
    gem 'fakeweb', '1.3.0' 
    gem 'capistrano', '2.13.5' 
    gem 'ruby-debug-ide', '0.4.7' 
    gem 'letter_opener', '1.1.0' 
end 

TO :

group :development, :test do 
    gem 'mocha', '~> 0.14', :require => false 
    gem 'vcr', '~> 2.5' 
    gem 'fakeweb', '1.3.0' 
    gem 'capistrano', '~> 2.15' 
    gem 'ruby-debug-ide', '0.4.17', :require => false 
    gem 'letter_opener', '~> 1.1' 
end 
0

내가 url_helper 모듈이 나를 위해 작동하지 않습니다 포함하는 오류에서 언급 한 같은 문제에 직면했다. 대신

messages_path(@message) 같은 경로 도우미 메서드의

include Rails.application.routes.url_helpers 

그래서 사용한 사용자 정의 URL은 나를 위해 작동 "/messages/@message.id"

로 변경되었습니다.