首页 文章

子域名ActionView :: Template ::错误(缺少要链接的主机!)

提问于
浏览
6

我已经完成了 Headers 中描述的错误的众多解决方案 .

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 implode"并重新开始多次

  • 团队的其他成员通常在Mac上本地开发,而我正在远程开发Ubuntu机器 .

  • 我以root身份工作(这有关系吗?)

在1889ms完成500内部服务器错误

ActionView :: Template :: Error(缺少要链接的主机!请提供:host参数,设置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 => "Contently",:src => "/images/logo_beta_premium.png"} / 7:-else app / helpers / url_helper.rb:16:in url_for' app/views/shared/_logged_in_writer_nav.html.haml:4:in _app_views_shared__logged_in_writer_nav_html_haml__656388632_107925510'app / views / layouts / application.html.haml:35:35:在 block in _app_views_layouts_application_html_haml__193634629_107212530' app/helpers/application_helper.rb:15:in html5_haml_tag'app / views / layouts / application.html.haml:2:in _app_views_layouts_application_html_haml__193634629_107212530' app/controllers/application_controller.rb:18:in error_generic'

1 回答

  • 6

    问题是您正在使用url帮助程序而不提供用于应用程序的默认主机 . *_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
    

    Edit:

    您可以使用 *_path 完全避免此问题

    > link_to "All Blogs", root_path
    #=> <a href="/">All Blogs</a>
    

相关问题