I''m trying to have my website on both http and https using the request object as in the documentation: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html I''ve tried many configurations and many combinations, right now this is what I have in my environment/staging.rbconfig.action_controller.asset_host = Proc.new { |source, request=nil| if request && request.ssl? "https://staging.foobar.it" else "http://assets#{ ( source.length % 4 ) + 1 }.staging.foobar.it" end } with this solution it appears like the request object is always set at nil. I''m using Ruby 1.9.3 and rails 3.2.12, with nginx as reverse proxy and unicorn as app server, and precompiling my assets Has someone been able to configure this and have the https website link to the right https asset server? What am I doing wrong? TIA, ngw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zZT2Qss6uqYJ. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, March 7, 2013 11:45:22 AM UTC+1, ngw wrote:> CUTSorry for the formatting config.action_controller.asset_host = Proc.new { |source, request=nil| if request && request.ssl? "https://staging.foobar.it" else "http://assets#{ <http://assets/#%7B> ( source.length % 4 ) + 1 }. staging.foobar.it" end } Hope it''s more clear. It''s bascially copied from the docs :) ngw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/__XJh0sPS4cJ. For more options, visit https://groups.google.com/groups/opt_out.
On 7 March 2013 10:49, ngw <ngw-joN+ekMQmMEdnm+yROfE0A@public.gmane.org> wrote:> On Thursday, March 7, 2013 11:45:22 AM UTC+1, ngw wrote: >> >> CUT > > > Sorry for the formatting > > config.action_controller.asset_host = Proc.new { |source, request=nil|Why have you got request=nil in the line above? Colin> if request && request.ssl? > "https://staging.foobar.it" > else > "http://assets#{ ( source.length % 4 ) + 1 }.staging.foobar.it" > end > } > > Hope it''s more clear. It''s bascially copied from the docs :) > > ngw > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/__XJh0sPS4cJ. > > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, March 7, 2013 12:45:05 PM UTC+1, Colin Law wrote:> On 7 March 2013 10:49, ngw <n...-joN+ekMQmMEdnm+yROfE0A@public.gmane.org <javascript:>> wrote: > > On Thursday, March 7, 2013 11:45:22 AM UTC+1, ngw wrote: > >> > >> CUT > > > > > > Sorry for the formatting > > > > config.action_controller.asset_host = Proc.new { |source, request=nil| > > Why have you got request=nil in the line above?Because if not I get $ RAILS_ENV=staging bundle exec rake assets:precompile rake aborted! This asset host cannot be computed without a request in scope. Remove the second argument to your asset_host Proc if you do not need the request. Seems a bug in Rails to me honestly... ngw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Zg2ooMZSg3IJ. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, March 7, 2013 10:49:48 AM UTC, ngw wrote:> > On Thursday, March 7, 2013 11:45:22 AM UTC+1, ngw wrote: > >> CUT > > > Sorry for the formatting > > config.action_controller.asset_host = Proc.new { |source, request=nil| > if request && request.ssl? > "https://staging.foobar.it" > else > "http://assets#{ <http://assets/#%7B> ( source.length % 4 ) + 1 }. > staging.foobar.it" > end > } > >Hope it''s more clear. It''s bascially copied from the docs :)> >Looking at the code, rails uses the arity of your proc to decide what to do. If the arity is 1 it passes just the source, if it is 2 it passes both, but will blow up when there is no request available (and warn you to) and if the arity is negative (you can pass as many optional arguments as you want) it passes both. the problem is that lambda {|x,y=nil|} counts as an arity of 1, so rails doesn''t try to pass the request, if you do lambda {|x,*y|} then you should get the request in y (y will be an array). However, you will presumably still need to deal with the fact that your precompiled assets will be either all ssl or all non ssl - if you serve some css that references (eg via background-url) a non ssl asset then I''d expect you to run into mixed content warnings. Fred> ngw >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/qxCa_pJP8ugJ. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, March 7, 2013 2:48:33 PM UTC+1, Frederick Cheung wrote:> Looking at the code, rails uses the arity of your proc to decide what to > do. If the arity is 1 it passes just the source, if it is 2 it passes both, > but will blow up when there is no request available (and warn you to) and > if the arity is negative (you can pass as many optional arguments as you > want) it passes both. > > the problem is that lambda {|x,y=nil|} counts as an arity of 1, so rails > doesn''t try to pass the request, if you do lambda {|x,*y|} then you should > get the request in y (y will be an array). > > However, you will presumably still need to deal with the fact that your > precompiled assets will be either all ssl or all non ssl - if you serve > some css that references (eg via background-url) a non ssl asset then I''d > expect you to run into mixed content warnings. >That''s exactly it, thanks a lot. Maybe Rails docs should be corrected? ngw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/B4gLlS336HMJ. For more options, visit https://groups.google.com/groups/opt_out.