이전 글에서 레일스를 배포할 때 sub-URI로 서비스할 경우 이미지 링크가 보이지 않았던 것에 대한 해결책을 소개한 바 있습니다.
사실 이 문제가 발생하자마자, wmd-editor 개발자(https://github.com/chloerei)에서 이메일을 보내어 해결책을 질문했었는데, 답장이 왔더군요. 내용은 다음과 같습니다.
Have you set
config.action_controller.relative_url_root = '/rorlab'
in config/environments/production.rb ?
sass-rails
will get the config and add prefix with assets-path.(test in rails3.2.3)
production.rb 파일에 config.action_controller.relative_url_root = “/app-name” 한 줄이면 해결되는 것을 …. ㅠㅠ 이전 해결책보다는 Chloerei의 것이 더 우선책이 될 것 같습니다.
역시 모르면, 고생입니다.
Thank you, Chloerei~
또 다른 방법을 알려 줬습니다.
하드코딩을 하지 않는 방법인데… precompile할 때 환경변수를 지정하는 방법과 다른 하나는 cap 레시피에 :asset_env 환경변수를 지정해 주는 것입니다.
아래는 Chloerei가 보내준 내용입니다.
I found another way to define relative url, avoid hard code. When precompile, set ENV
RAILS_RELATIVE_URL_ROOT=/rorlab bundle exec rake assets:precompile
Using cap, add a set.
set :asset_env, "RAILS_GROUPS=assets RAILS_RELATIVE_URL_ROOT=/rorlab"