On 8/8/05, bryce benton <brycebenton@gmail.com>
wrote:> link_to 'Proceed to checkout', url_for(:controller =>
'store', :action
> => "checkout", :protocol => 'https://')
>
> Why doesn't this line convert the link to https ?
>
> I've also tried using the strings 'http', 'HTTP',
'HTTP://' for
> :protocol, to no avail.
>
> In the meantime, I've hardcoded my link, but I really hate to do that.
> What am I missing here?
I've stumbled on this as well, the reason is simple though (once you
look around a bit), but not too obvious:
url_helper.rb:
module UrlHelper
def url_for(options = {}, *parameters_for_method_reference)
options = { :only_path => true
}.update(options.symbolize_keys) if options.kind_of? Hash
@controller.send(:url_for, options, *parameters_for_method_reference)
end
So, as you can see here it sets :only_path => true so you'll get urls
like /controller/action instead of
http://example.com/controller/action when linking from views, which is
nice since it doesn't screws up logfiles too much and such, however,
it's slightly painful since not all of the url_for options are
obviously not available when :only_path is true:
":only_path — if true, returns the absolute URL (omitting the
protocol, host name, and port)"
A possible solution is writing your own link_to helper (like
link_to_fullpath) and model it after the link_to in the UrlHelper
module, but without adding the :only_path option.
Cheers,
JS
--
http://johansorensen.com
http://theexciter.com
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails