我有一个控制器,它应该显示一条闪光消息。不显示闪烁消息。我唯一的问题是没有显示闪存消息。如果有人可以请对此做出解释,那将是很棒的。我猜我的错误是愚蠢的,但我不知道足以解释发生了什么。
编辑:我为此部分添加了我的日志
编辑:当我单击带有无效信息的管理按钮时,没有任何反应。当我刷新页面时,会显示 Flash 消息。我真的只需要刷新当前页面,但它不起作用。如果有人有任何想法,请分享。
编辑:我尝试将事情更改为
redirect_to @department, :notice => "invalid Password"
我仍然无法让 Flash 消息显示。
编辑:从这个站点它说现在闪存将显示在您正在渲染的视图中。但我渲染的视图是局部的。谁能至少让我知道我是否走在正确的轨道上。除了我自己的一点方向或想法吗?
这是我的关系的创建方法。
def create
@department = Department.find(params[:manager_relationship][:department_id])
if @department.authenticate(params[:manager_relationship][:password])
current_user.manage!(@department)
respond_to do |format|
format.html { redirect_to @department }
format.js
end
else
redirect_to department_path@department, :alert => "Invalid Password"
end
end
在我的会话控制器中成功使用了相同的代码。
SessionsController
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
它是从部分调用的
部门/show.hmtl.erb
<% provide(:title, @department.department_name) %>
<div class="span8">
<%= render 'manage_form' if signed_in? %>
</div>
_manage_form.html.erb
<div id="manage_form">
<% if current_user.managing?(@department) %>
<%= render 'unmanage' %>
<% else %>
<%= render 'manage' %>
<% end %>
</div>
_manage.html.erb
<%= form_for(current_user.manager_relationships.build(department_id: @department.id), remote: true) do |f| %>
<div>
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div><%= f.hidden_field :department_id %></div>
<%= f.submit "Manage department", class: "btn btn-large btn-primary" %>
<% end %>
应用程序.html.erb
<!DOCTYPE html>
<html>
<head>
.
.
.
...
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
</div>
这是取消管理和管理 http 请求的日志
Started DELETE "/manager_relationships/22" for 127.0.0.1 at 2013-03-24 11:08:20 -0700
Processing by ManagerRelationshipsController#destroy as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Y3I7qY4LBfChjdYAUlJ1eDh23YkcJRwSRfa6s2wavoI=", "commit"=>"Unmanage", "id"=>"22"}
[1m[36mUser Load (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."remember_token" = '9J1RAJy16Tooz5wMmzQohw' LIMIT 1[0m
[1m[35mManagerRelationship Load (0.0ms)[0m SELECT "manager_relationships".* FROM "manager_relationships" WHERE "manager_relationships"."id" = ? LIMIT 1 [["id", "22"]]
[1m[36mDepartment Load (1.0ms)[0m [1mSELECT "department".* FROM "departments" WHERE "department"."id" = 1 LIMIT 1[0m
[1m[35mManagerRelationship Load (0.0ms)[0m SELECT "manager_relationships".* FROM "manager_relationships" WHERE "manager_relationships"."user_id" = 1 AND "manager_relationships"."department_id" = 1 LIMIT 1
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
[1m[35mSQL (0.0ms)[0m DELETE FROM "manager_relationships" WHERE "manager_relationships"."id" = ? [["id", 22]]
[1m[36m (26.0ms)[0m [1mcommit transaction[0m
Rendered departments/_manage.html.erb (2.0ms)
Rendered manager_relationships/destroy.js.erb (5.0ms)
Completed 200 OK in 86ms (Views: 11.0ms | ActiveRecord: 27.0ms)
Started POST "/manager_relationships" for 127.0.0.1 at 2013-03-24 11:08:23 -0700
Processing by ManagerRelationshipsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Y3I7qY4LBfChjdYAUlJ1eDh23YkcJRwSRfa6s2wavoI=", "manager_relationship"=>{"password"=>"[FILTERED]", "department_id"=>"1"}, "commit"=>"Manage Bar"}
[1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."remember_token" = '9J1RAJy16Tooz5wMmzQohw' LIMIT 1
[1m[36mDepartment Load (0.0ms)[0m [1mSELECT "departments".* FROM "departments" WHERE "departments"."id" = ? LIMIT 1[0m [["id", "1"]]
Redirected to http://localhost:3000/departments/1
Completed 406 Not Acceptable in 91ms (ActiveRecord: 0.0ms)