This project is archived and is in readonly mode.

#2436 ✓stale
j0llyr0g3r

url_for documentation - only_path

Reported by j0llyr0g3r | April 7th, 2009 @ 12:54 AM | in 3.x

The description for url_for: http://api.rubyonrails.org/class...

is slightly wrong, it says:

:only_path - If true, returns the relative URL (omitting the protocol, host name, and port) (false by default).

I tested it on rails 2.2 and rails 2.3 and it is the other way round: it is "true" by default, not false.

E.g. this: url_for(:controller => 'shoppingcarts', :action => 'error')

gives me the relative url /shoppingcarts/error, but this:

url_for(:controller => 'shoppingcarts', :action => 'error', :only_path => false)

gives me the absolute url http://...../shoppingcarts/error

So i think the sentence should read:

:only_path - If true, returns the relative URL (omitting the protocol, host name, and port) (true by default).

Comments and changes to this ticket

  • heidmo

    heidmo April 21st, 2009 @ 02:08 AM

    • Assigned user set to “CancelProfileIsBroken”

    Yeah I agree, it should say "(true by default)" instead of false.

  • CancelProfileIsBroken
  • Derek McLoughlin

    Derek McLoughlin June 22nd, 2009 @ 05:01 PM

    url_for behaves differently depending on whether it is called from within a view or within a controller.

    From within a view, the default is a relative URL, and :only_path => false gives you the full URL.

    From within a controller, the default is a full URL, and :only_path => true gives you the relative URL.

    Sample code with a scaffold 'Person'

    Controller:
    @@@ruby def show

    @person = Person.find(params[:id])
    
    @person_url = url_for(@person)
    @person_url_only_path_false = url_for(:id => params[:id], :only_path => false)
    @person_url_only_path_true = url_for(:id => params[:id], :only_path => true)
    

    end

    
    show.rhtml
    @@@ruby
    <p>IN THE VIEW</p>
    <p>url_for(@person) = <%= url_for(@person) %></p>
    <p>url_for(:id => 1, :only_path => false) = <%= url_for(:id => 1, :only_path => false) %></p>
    <p>url_for(:id => 1, :only_path => true) = <%= url_for(:id => 1, :only_path => true) %></p>


    <p>FROM THE CONTROLLER</p> <p>url_for(@person) = <%= @person_url %></p> <p>url_for(:id => 1, :only_path => false) = <%= @person_url_only_path_false %></p> <p>url_for(:id => 1, :only_path => true) = <%= @person_url_only_path_true %></p>

    The documentation is correct.

  • Andrew Vit

    Andrew Vit January 1st, 2010 @ 01:15 AM

    IMHO, it would read better if the option were named :full_url, :full_path, or :fully_qualified.

    It's always clearer if the option is stated as a positive, so the default can be false. (For that matter, why isn't there a path_for method like with the other url helper methods?)

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:39 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:39 PM

    • State changed from “open” to “stale”
  • klkk

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages