Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.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 flash消息不';不显示_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails flash消息不';不显示

Ruby on rails Rails flash消息不';不显示,ruby-on-rails,Ruby On Rails,我出去了。。。3个小时,还是什么都没有。我在application_controller.rb中为我的应用程序制作了before_过滤器: def fill_profile unless current_user.profile.state_id.present? flash[:add_state] = 'add_state' return respond_to do |format| format.html { redirect_to edit_profile_path(cu

我出去了。。。3个小时,还是什么都没有。我在application_controller.rb中为我的应用程序制作了before_过滤器:

def fill_profile

unless current_user.profile.state_id.present?
  flash[:add_state] = 'add_state'
  return respond_to do |format|
    format.html { redirect_to edit_profile_path(current_user.profile) }
  end
end
end
class AssetsController < ApplicationController

  before_filter :fill_profile

end
现在是assets_controller.rb:

def fill_profile

unless current_user.profile.state_id.present?
  flash[:add_state] = 'add_state'
  return respond_to do |format|
    format.html { redirect_to edit_profile_path(current_user.profile) }
  end
end
end
class AssetsController < ApplicationController

  before_filter :fill_profile

end
class AssetController
资产控制器中的索引操作为空。我按下链接:

<%= link_to 'abc', assets_path %>

什么都没有。。。没有即时消息。对于每一个其他控制器,在过滤器工作之前,只有资源控制器不工作。有人能帮忙吗

在before_筛选器中没有重定向,只有此重定向。当我只在过滤器前放入flash消息而不将其重定向到时,它甚至对资产控制器也有效

我还为消息创建了相同的链接:

<%= link_to 'def', messages_path %>
<div id="flash_messages">
  <% flash.each do |key, value| %>
    <%= render :partial => 'shared/flash_element', :locals => { :key => key.to_s.downcase, :value => value } %>
   <% end %>
 </div>

而且,同样的空消息_controller.rb只有在_filter之前才有-而且它可以工作

查看flash消息:

<%= link_to 'def', messages_path %>
<div id="flash_messages">
  <% flash.each do |key, value| %>
    <%= render :partial => 'shared/flash_element', :locals => { :key => key.to_s.downcase, :value => value } %>
   <% end %>
 </div>

'shared/flash_element',:locals=>{:key=>key.to_.s.downcase,:value=>value}%>

是否在布局文件中显示闪存?您是否使用与其他控制器中相同的布局?您能否发布如何打印flash消息?是的,我在wrapper div中的每个页面都有相同的视图。每个flash都可以工作,但不适用于控制器。但我如何呈现它并不重要。Eveny不会仅为控制器显示flash。我删除了项目中的所有内容。没有其他仅限控制器的消息和资源。对于我看到的flash消息,对于资产没有。现在我非常惊讶。我打开我的老项目时也会发出同样的闪光信息。而且,这种类型的before\u过滤器不仅适用于资产\u控制器。它不确定index.html.erb是否为空。不测量控制器中的def索引是否为空。Flash不起作用:)回形针可能是个问题,事实上,那个资产有附加文件吗?