我有部分问题。我正在尝试使用bootstrap创建闪存,并且我已经在互联网上找到了我发现的东西,这是有道理的。但它不起作用。错误显示显示C:/ Users / David Soler / Desktop / diabetes_app / app / views / layouts / application.html.erb,其中第15行引发:
Missing partial shared/_flash_messages with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in:
* "C:/Users/David Soler/Desktop/diabetes_app/app/views"
* "C:/Ruby21/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"
这是我的代码:
_flash_messages_html.erb
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>DiabetesApp</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag "application", :defer => "defer" %>
<%= javascript_include_tag params[:controller], :defer => "defer" %>
<%= csrf_meta_tags %>
<script defer>
</script>
</head>
<body>
<%= render partial: "shared/flash_messages", flash: flash %>
<%= yield %>
</body>
</html>
application_helper.rb
module ApplicationHelper
def bootstrap_class_for flash_type
case flash_type
when :success
"alert-success"
when :error
"alert-error"
when :alert
"alert-block"
when :notice
"alert-info"
else
flash_type.to_s
end
end
end