1
私はペーパークリップオブジェクトのasset_hostで絶対URLを取得するためのソリューションを探しています。 urlメソッドは相対URLのみを返します。だから私はこれを試しました:paperclip url to return asset_host
Paperclip::Attachment.default_options.update({
:url => "#{ActionController::Base.asset_host.call(nil, request)}/system/:attachment/:id/:style/:filename",
:path => ":rails_root/public/system/:attachment/:id/:style/:filename"
})
しかし、要求がイニシャライザにありません。または私はそれをどのように取得するのですか?
私asset_hostの設定は次のようになります。
ActionController::Base.asset_host = Proc.new do |source, request|
if request.ssl?
"#{request.protocol}#{request.host_with_port}"
else
"http://cdn.somehost.com"
end
end
私はこれにこだわっています!
お世話になりました!
素晴らしいです!ありがとうございました! – Oliver
素晴らしい!私はコントローラーの中と外にブロックする必要はないと思う。代わりに私は '#{request.protocol}#{request.host_with_port}' – brutuscat
を使ってビューヘルパーをやっていましたが、遅れたメールやバックグラウンドジョブのような非要求環境下で動作させるための回避策が必要です。 – lidaobing