Mark Kremer
2011-Sep-01 10:10 UTC
How can I get the URL to an asset in the asset pipeline outside of my views?
Hello everyone, I''m working on a Rails app that uses an external asset host for images and such. I''ve got my app configured to use the asset host in the environment file. The URL to the asset host is properly rendered when using an image_tag in the view per example (it will correctly set the src to http://asset.host.url/assets/myimage.png instead of /assets/myimage.png). I''m using paperclip to attach images to my models, and I want to specify a default URL for models that don''t have an image. I traced the logic being used by image_tag to ActionView::Helpers::AssetTagHelper::AssetPath#compute_public_path, but I can''t seem to figure out how to call this logic from outside of my views. Can anyone enlighten me as to how to do this correctly? Regards, Mark -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mark Kremer
2011-Sep-01 18:24 UTC
Re: How can I get the URL to an asset in the asset pipeline outside of my views?
In the meantime I''ve figured out a way to get what I want: ActionController::Base.new.view_context.asset_path "myimage.png" On 09/01/2011 12:10 PM, Mark Kremer wrote:> Hello everyone, > > I''m working on a Rails app that uses an external asset host for images > and such. I''ve got my app configured to use the asset host in the > environment file. The URL to the asset host is properly rendered when > using an image_tag in the view per example (it will correctly set the > src to http://asset.host.url/assets/myimage.png instead of > /assets/myimage.png). > > I''m using paperclip to attach images to my models, and I want to > specify a default URL for models that don''t have an image. I traced > the logic being used by image_tag to > ActionView::Helpers::AssetTagHelper::AssetPath#compute_public_path, > but I can''t seem to figure out how to call this logic from outside of > my views. > > Can anyone enlighten me as to how to do this correctly? > > Regards, > Mark >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.