Saturday, February 16, 2013

Playing with URL Helpers in Rails 3.2 Console


 :001 > Rails.application.routes
 => # 
 :002 > Rails.application.routes.url_helpers
 => # 
 :003 > Rails.application.routes.url_helpers.permissions_get_access_token_url
ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
 :004 > Rails.application.routes.url_helpers.permissions_get_access_token_path
 => "/permissions/get_access_token"
 :005 > Rails.application.routes.url_helpers.permissions_get_access_token_path(:host => 'http://localhost')
 => "/permissions/get_access_token"
 :006 > Rails.application.routes.url_helpers.permissions_get_access_token_url(:host => 'http://localhost')
 => "http://http://localhost/permissions/get_access_token"
 :007 > Rails.application.routes.url_helpers.permissions_get_access_token_url(:host => 'localhost')
 => "http://localhost/permissions/get_access_token"
 :008 > Rails.application.routes.url_helpers.permissions_get_access_token_url(:host => 'localhost:3000')
 => "http://localhost:3000/permissions/get_access_token"

 or

  :001 > include ActionDispatch::Routing
  => Object
  :002 > include Rails.application.routes.url_helpers
  => Object
  :003 > permissions_path
  => "/permissions"
  :004 > permissions_url
 ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
  from /Users/bparanj/.r

Reference:
Recognizing URL Helpers