简体   繁体   English

链接到主页呈现空白

[英]Link to home page renders blank

In my rails app, I have a link to the root that renders in all browsers as 在我的rails应用程序中,我有一个指向根的链接,该根在所有浏览器中均显示为

<html>
  <head>
    <style type="text/css"></style>
  </head>
  <body>19</body>
</html>

Server-side I can see all assets getting passed back. 服务器端,我可以看到所有资产都传回了。 For some reason the browser will not display them because if I view page source I can see ALL my markup correctly. 出于某种原因,浏览器将不会显示它们,因为如果我查看页面源代码,则可以正确看到所有标记。

Now if I load or reload the page localhost:3000 normally the page and all assets are displayed correctly. 现在,如果我正常加载或重新加载页面localhost:3000,则该页面和所有资产都将正确显示。 If I simply refresh I get nothing. 如果我只是刷新,我什么也没得到。

The only time this occurs is when I click a link back to the homepage like a href="/". 发生这种情况的唯一时间是当我单击指向首页的链接,如href =“ /”时。

The behavior does not occur if I hardcode a href="localhost:3000/" but I don't want to do this. 如果我对href =“ localhost:3000 /”进行硬编码,则不会发生此行为,但是我不想这样做。

Rails app, Turbolinks, nowhere in code do I use the number 19, rake routes with root GET well-defined, no public/index.html. Rails应用程序,Turbolinks,在代码中我都没有使用数字19,耙根定义明确的GET路由,没有public / index.html。 I suspect something to the degree of caching or turbolinks but I have no clue how to resolve. 我怀疑某种程度的缓存或turbolinks,但我不知道如何解决。

Edit: Config/Routes.rb 编辑:Config / Routes.rb

SCRR::Application.routes.draw do
   root 'home#index'
   #pages
   get 'about' => 'pages#about'
   get 'history' => 'pages#history'
   get 'links' => 'pages#links'
   get 'safety' => 'pages#safety'
   get 'membership' => 'pages#membership'
   get 'events' => 'events#index'
   get 'grand_prix' => 'grand_prix#index'
   get 'newsletters' => 'newsletters#index'
end

Edit 2: Chrome Devtools Console Errors 编辑2:Chrome Devtools控制台错误

This error is probably more relevant 该错误可能更相关

Resource interpreted as Font but transferred with MIME type application/x-woff: " https://netdna.bootstrapcdn.com/font-awesome/2.0/font//fontawesome-webfont.woff ". 资源被解释为Font,但以MIME类型application / x-woff转移:“ https://netdna.bootstrapcdn.com/font-awesome/2.0/font//fontawesome-webfont.woff ”。

jquery-2.1.0.js?body=1:1078 ?jquery的-2.1.0.js体= 1:1078

25115 : CS -> BG : FAILED closepopuptoplevel 25115:CS-> BG:失败closepopuptoplevel

onloadwff.js:77 onloadwff.js:77

From what you've posted, I don't know whether this would be a Rails issue or a browser issue. 从您发布的内容来看,我不知道这是Rails问题还是浏览器问题。

I see you've tagged turbolinks , which could be a contributor to the issue; 我看到您已经标记了turbolinks ,这可能是导致该问题的原因。 so let's have a look as to what the problem might be for you: 因此,让我们来看看问题可能是什么:


ERB ERB

The ERB code you should use should be the following: 您应使用的ERB代码应如下所示:

<%= link_to "Home", root_path %>

If you're trying to reference the "home" url directly, there may be an issue with how you're rendering the URL, hence why it won't show. 如果您尝试直接引用“ home” URL,那么如何呈现URL可能会有问题,因此为什么它不会显示。 You should ensure you use the path helper as described above. 您应确保如上所述使用path helper

This should be coupled with the correct routes: 这应该结合正确的路线:

#config/routes.rb
root "home#index"
resources :pages, path: "" do
  collection do
    get :about
    get :history
    get :links
    get :safety
    get :membership
    get :events
    get :grand_prix
    get :newsletters
  end
end

Assets 资产

You mention the assets don't render when you refresh the page, this could be an issue with Turbolinks , although I'm not sure 您提到刷新页面时资产未呈现,这可能Turbolinks的问题,尽管我不确定

Turbolinks basically just reloads the <body> of the page, leaving the <head> intact. Turbolinks基本上只是重新加载页面的<body> ,而保持<head>不变。 Although this might sound like nothing to do with your issue, perhaps the problem is to do with the way in which Turbolinks is working with your assets 尽管这听起来似乎与您的问题无关,但问题可能出在Turbolinks处理资产的方式上

From your edit, it may appear that your assets are not loading correctly, or are at least not being shown correctly. 从您的编辑看来,您的资产可能没有正确加载,或者至少没有正确显示。

I hope this helps, I doubt it will give you a constructive answer 我希望这会有所帮助,我怀疑这会给您一个建设性的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM