【发布时间】:2014-06-04 22:22:48
【问题描述】:
我目前正在开发一个网络应用程序,但遇到了一个小问题。我的视图控制器中有一个 redirect_to root_path 语句,如果逻辑语句返回 true,则调用该语句。在被重定向到的页面上,我在布局视图中有一个 stylesheet_link_tag。当我手动拉出页面时,此标签会正确加载。但是,在使用 redirect_to 语句并从中加载此页面后,样式表标记不再存在。它仍然加载 application.css 文件和我的 application.js 文件而没有任何问题,但 pagename.css 链接标记甚至没有显示。
页面的显示方式如下:
然后一旦我刷新:
请帮助我!我很想知道为什么会发生这种情况以及如何解决它。提前谢谢!
以下是所有相关代码位:
users_controller.rb
...
def logout
cookies[:logged_in] = false
cookies[:user_id] = 0
redirect_to root_path # Tried using root_url also; didn't fix the problem.
end
...
主页/index.html.erb (root_path)
A bunch of HTML. Not the problem.
layouts/homepage.html.erb
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'homepage' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="header_container">
<%= link_to "#{image_tag 'logo.png'}".html_safe, root_path %>
<div class="login tab">
<span>
Login
<%= image_tag "down_arrow.png" %>
</span>
<%= form_tag login_path, :method => 'post' do %>
<% end %>
</div>
<div class="register tab">
<span>
<%= link_to "Register", register_path, "data-ajax" => "false", :rel => false %>
</span>
</div>
</div>
<div id="main_container">
<%= yield %>
</div>
</body>
</html>
我必须将 homepage.css 资产添加到 config/locales/application.rb,所以这是:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module Labs
class Application < Rails::Application
config.assets.precompile += %w( homepage.css )
config.assets.precompile += %w( dropdown.js )
end
end
【问题讨论】:
-
控制台说什么?
-
在 2014-06-04 20:18:50 -0500 开始 GET "/register" for 127.0.0.1 由 UsersController#register 处理为 HTML 渲染 users/register.html.erb 在 layouts/register .html.erb (2.0ms) 在 15ms 内完成 200 OK (查看次数: 14.0ms | ActiveRecord: 0.0ms) [2014-06-04 20:18:50] WARN 无法确定响应正文的内容长度。设置响应的内容长度或设置 Response#chunked = true
标签: html css ruby-on-rails