2012-10-18 25 views
6

我已經完成了標題中描述的錯誤的衆多解決方案。Subdomains + ActionView :: Template :: Error(缺少鏈接到的主機!)

ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):

然而,這個項目還修改了url_for功能使用子域名,如在此railscast:

http://railscasts.com/episodes/221-subdomains-in-rails-3

因此,傳統的答案,這樣的錯誤,這樣的因爲在我的環境設置中設置變量似乎不是解決方案。

下面是其他一些提示:

  • 這是新成立的一個品牌,我剛纔克隆​​一個項目,安裝紅寶石,鐵軌,寶石等
  • 我已經試過「RVM內爆」和多次開始
  • 團隊的其他成員通常在Mac上本地開發,而我正在遠程開發Ubuntu機器。
  • 我的工作,作爲root(做這件事?)

完成500內部服務器錯誤1889ms

::的ActionView ::模板錯誤(缺少主機鏈接到請提供!主機參數,設置default_url_options [:host],或設置:only_path爲true): 1:%header.menu {:role =>「banner」} 2:.col980 3:%h1 4:%a。 logo {:href => root_url({:subdomain => false})} 5:-if current_user.premium? 6:%IMG {:ALT => 「滿足地」,:SRC =>「/images/logo_beta_premium.png"}/ 7:-else 應用程序/助手/ url_helper.rb:16:在url_for' app/views/shared/_logged_in_writer_nav.html.haml:4:in _app_views_shared__logged_in_writer_nav_html_haml__656388632_107925510' 應用/views/layouts/application.html.haml:35:in block in _app_views_layouts_application_html_haml__193634629_107212530' app/helpers/application_helper.rb:15:in html5_haml_tag ' 應用程序/視圖/佈局/ application.html.haml:2:_app_views_layouts_application_html_haml__193634629_107212530' app/controllers/application_controller.rb:18:in error_generic'

回答

6

的問題是,您使用的是網址幫助程序而不提供用於應用程序的默認主機。 *_url的神奇之處在於,它會在鏈接中返回路徑以及基礎網址

例如,如果您的默認URL中的域名是example.com:

> link_to "All Blogs", root_url(:subdomain => false) 
#=> <a href="http://example.com/">All Blogs</a> 

您可以通過添加以下行環境配置文件的底部設置在config/environments/*.rb文件的默認主持人你」重新在

config.before_initialize do                                                  
    MyApp::Application.routes.default_url_options[:host] = 'myapp.com' 
end 

編輯:

您可以完全使用0避免這個問題

> link_to "All Blogs", root_path 
#=> <a href="/">All Blogs</a> 
相關問題