Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7542

Show
Ignore:
Timestamp:
09/22/07 17:19:26 (1 year ago)
Author:
david
Message:

Fixed that setting the :host option in url_for would automatically turn off :only_path (since :host would otherwise not be shown) (closes #9586) [Bounga]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r7541 r7542  
    11*SVN* 
     2 
     3* Fixed that setting the :host option in url_for would automatically turn off :only_path (since :host would otherwise not be shown) #9586 [Bounga] 
    24 
    35* Added FormHelper#label #8641 [jcoglan] 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r7096 r7542  
    2121      # ==== Options 
    2222      # * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. 
    23       # * <tt>:only_path</tt> --  if true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default
     23      # * <tt>:only_path</tt> --  if true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default unless <tt>:host</tt> is specified
    2424      # * <tt>:trailing_slash</tt> --  if true, adds a trailing slash, as in "/archive/2005/". Note that this 
    2525      #   is currently not recommended since it breaks caching. 
     
    6666        case options 
    6767        when Hash 
    68           options = { :only_path => true }.update(options.symbolize_keys) 
     68          show_path =  options[:host].nil? ? true : false 
     69          options = { :only_path => show_path }.update(options.symbolize_keys) 
    6970          escape  = options.key?(:escape) ? options.delete(:escape) : true 
    7071          url     = @controller.send(:url_for, options) 
  • trunk/actionpack/test/template/url_helper_test.rb

    r7096 r7542  
    8383    assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com") 
    8484  end 
     85   
     86  def test_link_tag_without_host_option 
     87    ActionController::Base.class_eval { attr_accessor :url } 
     88    url = {:controller => 'weblog', :action => 'show'} 
     89    @controller = ActionController::Base.new 
     90    @controller.request = ActionController::TestRequest.new 
     91    @controller.url = ActionController::UrlRewriter.new(@controller.request, url) 
     92    assert_dom_equal(%q{<a href="/weblog/show">Test Link</a>}, link_to('Test Link', url)) 
     93  end 
     94 
     95  def test_link_tag_with_host_option 
     96    ActionController::Base.class_eval { attr_accessor :url } 
     97    url = {:controller => 'weblog', :action => 'show', :host => 'www.example.com'} 
     98    @controller = ActionController::Base.new 
     99    @controller.request = ActionController::TestRequest.new 
     100    @controller.url = ActionController::UrlRewriter.new(@controller.request, url) 
     101    assert_dom_equal(%q{<a href="http://www.example.com/weblog/show">Test Link</a>}, link_to('Test Link', url)) 
     102  end 
    85103 
    86104  def test_link_tag_with_query 
     
    176194    assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") } 
    177195  end 
    178  
     196   
    179197  def test_link_to_unless 
    180198    assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog")