Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails设备未登录特定页面_Ruby On Rails_Ruby On Rails 3_Devise - Fatal编程技术网

Ruby on rails rails设备未登录特定页面

Ruby on rails rails设备未登录特定页面,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,当我登录时,它会重定向到根页面,但是如果用户\登录,它会在导航栏(标题)中出现吗?函数未执行,但在其他页面中,比如说/browse/audi,在标题中,它显示了带有注销的用户名,其余页面标识用户已登录,但登录页面除外 caches_page :index layout 'application_slide', only: [:index] layout 'car_model', only: [:car_model] before_filter :authenticate_user!, onl

当我登录时,它会重定向到根页面,但是如果用户\登录,它会在导航栏(标题)中出现吗?函数未执行,但在其他页面中,比如说/browse/audi,在标题中,它显示了带有注销的用户名,其余页面标识用户已登录,但登录页面除外

 caches_page :index

layout 'application_slide', only: [:index]
layout 'car_model', only: [:car_model]
before_filter :authenticate_user!, only: "step2"
根路径(即索引)的我的控制器

我的索引布局

<title><%= content_for?(:title) ? yield(:title) : "Nabthat" %></title>

<%= stylesheet_link_tag    "admin" %>

<%= csrf_meta_tags %>
</head>

<body class="login-layout off-canvas hide-extras" id="common-nav" cz-shortcut-listen="true">
 <%= render "/layouts/navbar" %>
 <%# render "/layouts/flash" %>
 <div class="row">
  <div class="main-container" id="main-container">
    <div class="main-container-inner">
      <%= yield %>
    </div>
  </div>
</div>

首先检查您的用户模型,它应该是user.rb而不是users.rb


否则,您可以使用当前用户方法检查用户是否已登录

登录前,
缓存页面:索引
正在缓存页面。然后,当您登录时,缓存页面将在不检查rails应用服务器的情况下返回(因此永远没有机会检查您是否登录)-nginx直接返回它(这将解释为什么curl接收到的响应头如此不同)

如果是这种情况,可以通过删除
缓存页面:index
来解决。如果确实需要缓存索引页,则可以在
..
块中包装所需的索引视图的任何部分(可能不会太多,因为看起来索引视图中也有动态内容-例如角色检查)。或者,如果您在Rails4上,您可能希望使用动作缓存或新的Rails4缓存方法

Rails 3.2缓存:


Rails 4缓存:

我的型号名称是user.rb,用户是否已登录?正在除根路径(即登录页)之外的其他页面中工作
<title><%= content_for?(:title) ? yield(:title) : "Nabthat" %></title>

<%= stylesheet_link_tag    "admin" %>

<%= csrf_meta_tags %>
</head>

<body class="login-layout off-canvas hide-extras" id="common-nav" cz-shortcut-listen="true">
 <%= render "/layouts/navbar" %>
 <%# render "/layouts/flash" %>
 <div class="row">
  <div class="main-container" id="main-container">
    <div class="main-container-inner">
      <%= yield %>
    </div>
  </div>
</div>
    <% if !user_signed_in? %>
    <li>
      <%= link_to "Log in", "#nav-login-modal",:data => {"toggle" => "modal"}, class: "li-pull-right"%>  
    </li><li>
      <%= link_to "List Your Dealership", new_user_registration_path, class: "list-dealer-new nav-list-dealer"%>
    </li>
    <% else %>
➜  nthat git:(master) ✗ curl -I https://nabthat.com/
HTTP/1.1 200 OK
Server: nginx/1.4.1 (Ubuntu)
Date: Fri, 07 Feb 2014 10:18:15 GMT
Content-Type: text/html
Content-Length: 21392
Last-Modified: Mon, 03 Feb 2014 09:04:20 GMT
Connection: keep-alive
ETag: "52ef5b94-5390"
Accept-Ranges: bytes

➜  nthat git:(master) ✗ curl -I https://nabthat.com/browse-car/Audi
HTTP/1.1 200 OK
Server: nginx/1.4.1 (Ubuntu)
Date: Fri, 07 Feb 2014 10:18:51 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 39651
Connection: keep-alive
Status: 200 OK
X-UA-Compatible: IE=Edge,chrome=1
ETag: "659ad8caeff9e921ced5ef8e3fa0d266"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: request_method=GET; path=/
X-Request-Id: 30d83bc2f036eedffe1a8fdb1be7405b
X-Runtime: 0.363171
X-Rack-Cache: miss