url_for
 
  url_for(options = {}, *parameters_for_method_reference)
  public
  Returns the URL for the set of options provided. This takes the same options as url_for. For a list, see the documentation for ActionController::Base#url_for. Note that it’ll set :only_path => true so you’ll get /controller/action instead of the http://example.com/controller/action part (makes it harder to parse httpd log files)
When called from a view, url_for returns an HTML escaped url. If you need an unescaped url, pass :escape => false to url_for.
 foliosus -  
    March 20, 2009
 foliosus -  
    March 20, 2009 
    
  Use the current URL, with changes
You can use the current URL, whatever it is, with changes, as in:
# Create a link to the current page in RSS form url_for(:overwrite_params => {:format => :rss})
This can be super-helpful because it preserves any GET params (like search parameters)
 javiervidal -  
    March  3, 2011
 javiervidal -  
    March  3, 2011 
    
  Using namespaces
If you are using a namespace in your routes.rb, for example:
namespace :admin do resources :products end
then you can:
url_for([:admin, @product])
and:
url_for([:edit, :admin, @product])
 tomharrisonjr -  
    August 24, 2012
 tomharrisonjr -  
    August 24, 2012 
    
  Specify :host option in emails
Emails need a fully qualified URL (with domain). Use the :host parameter.
But note also that you need to specify a value that is not dependent upon the request context. http://api.rubyonrails.org/classes/ActionMailer/Base.html recommends setting a default host in application.rb For those of us who have development, test, staging and production environments, set in the environment-specific files, or in the :default hash in the mailer.
This applies to both +url_for(:host => “example.com”)+ and when using named routes as in +widgets_url(:host => “example.com”)+

 RSpec
RSpec Ruby on Rails
Ruby on Rails Ruby
Ruby 
   
    
     
    
    
     
   
   
   
   
    