我正在关注有关rails的设计和cancan集成的教程。 https://github.com/RailsApps/rails3-bootstrap-devise-cancan 我注意到当用户登录闪存通知时会导致页面在关闭后重新加载。 我在日志中看到了这一点:重定向到“根路径”已完成302
这是我的路线文件
App::Application.routes.draw do
resources :videos do
collection do
post "delete_selected_item"
end
end
unauthenticated do
root :to => 'external#index'
match '/features' => 'external#features'
match '/pricing' => 'external#pricing'
end
devise_scope :user do
match '/sign_up' => 'devise/registrations#new'
match '/sign_in' => 'devise/sessions#new'
end
devise_for :users
authenticated :user do
root :to => "dashboard#index"
match 'dashboard/videos' => 'videos#index'
match 'dashboard/statistics' => 'statistics#index'
match 'dashboard/analytics' => 'analytics#index'
resources :users
end
post "zencoder-callback" => "zencoder_callback#create", :as => "zencoder_callback"
end
布局代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "BriteVid" %></title>
<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "BriteVid" %>">
<meta name="csrf-token" content="<%= form_authenticity_token %>" />
<meta name="csrf-param" content="authenticity_token" />
<%= stylesheet_link_tag "application", :media => "all" %>
<link href="https://vjs.zencdn.net/4.0/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/4.0/video.js"></script>
<%= javascript_include_tag "application" %>
<link href="<%= image_path("favicon.ico") %>" rel="shortcut icon" />
<%= csrf_meta_tags %>
<%= yield(:head) %>
</head>
<body class="<%=params[:controller].parameterize%> <%=params[:action].parameterize%>">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div id="nav_header">
<%= render 'dashboard/internal_header' %>
</div>
</div>
</div>
<%= render 'layouts/shared/alerts' %>
<div id="wrap">
<div id="main" role="main">
<%= render 'dashboard/dashnav' %>
<%= yield %>
<% if Rails.env.production? %> <%= render 'layouts/shared/ga' %><% end %>
</div>
</div>
<%= render 'layouts/shared/chat' %>
</body>
</html>
Flash消息代码
<div class="container">
<% if user_signed_in? %>
<% flash.each do |name, msg| %>
<div class="alert-<%= name == :notice ? "success" : "error" %> fade in">
<a class="close" data-dismiss="alert" href="">x</a>
<center><%= content_tag :div, msg, :id => "flash_#{name}" %></center>
</div>
<% end %>
<% end %>
</div>
答案 0 :(得分:0)
更改此
<a class="close" data-dismiss="alert" href="">x</a>
到这个
<a class="close" data-dismiss="alert" href="#">x</a>
现在,该页面将不再重定向到根网址。
<强> [编辑] 强>
href=""
标记中的空<a>
重新加载页面。所以,您可以将其更改为以下内容:
href="#"
在浏览器历史记录中添加了一个额外的条目(例如,在回扣时很烦人)。
href="javascript:;"
似乎没有任何问题(除了看起来凌乱无意义)
答案 1 :(得分:0)
您确定正确包含bootstrap javascript文件吗?
在application.js中应该是那一行:
//= require bootstrap