在我的用户编辑页面中,有一行如下:
<%= devise_error_messages! %>
Run Code Online (Sandbox Code Playgroud)
问题是这不是输出错误的标准方式,应用程序的其余部分:
<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何让设计错误消息像使用flash.each的其他人一样工作?
谢谢.
我正在将twitter bootstrap css集成到我的应用程序中.一直很好,但我不知道如何为我的flash消息自定义css和包装器.
我希望我的flash消息能够使用默认的Bootstrap类进行格式化:
<div class="alert-message error">
<a class="close" href="#">×</a>
<p><strong>Oh snap!</strong> Change this and that and <a href="#">try again</a>.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
目前我输出我的flash消息:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法可以运行一个小的开关:通知或其他rails flash消息映射到bootcamp中的类,如信息?
我试图在控制器中设置闪存通知,但似乎我只能定义:通知.当我尝试定义:errors或flash [:errors]时,我遇到了一堆错误.我目前有这个工作,但所有的消息显然是一个通知类型,而不是错误或警告.我想知道如何设置错误或警告而不是通知.我正在使用rails 3.2和twitter bootstrap rails gem
在application.html.erb中
<%= bootstrap_flash %>
Run Code Online (Sandbox Code Playgroud)
在 manuals_controller.rb
class ManualsController < ApplicationController
def create
respond_to do |format|
format.html { redirect_to root_url, notice:'MyManual was successfully created.' }
end
end
end
Run Code Online (Sandbox Code Playgroud) ruby-on-rails ruby-on-rails-3 flash-message twitter-bootstrap
即时通讯使用twitters bootstrap警报消息.在我的application.html.erb我有......
<% flash.each do |key, value| %>
<div class="alert alert-<%=key%>">
<a class="close" data-dismiss="alert">×</a>
<%= value %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
通常当我想做一个flash消息时,我会写一些类似的东西
flash[:success] = "Profile updated"
Run Code Online (Sandbox Code Playgroud)
但我不知道如何给设计错误消息一个键和值对.我查看了devise.en.yml,但似乎无法将消息与密钥相关联,即:成功,:错误等可能有人帮忙吗?谢谢!
我正在使用Rails 4,Twitter Bootstrap 3.0和Devise 3.0.我正在尝试为设计和我的网站的其余部分获得完全相同的flash消息.到目前为止,我有这个:
在"app/views/layouts/application.html.erb"中:
<%= render 'layouts/messages' %>
Run Code Online (Sandbox Code Playgroud)
"app/views/layouts/_messages.html.erb":
<% devise_flash %>
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>">
<a href="#" data-dismiss="alert" class="close">×</a>
<%= value %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我创建了一个"app/helpers/devise_helper.rb"来覆盖默认的设计错误消息:
module DeviseHelper
def devise_error_messages!
end
end
Run Code Online (Sandbox Code Playgroud)
"app/helpers/application_helper.rb":
def devise_flash
if controller.devise_controller? && resource.errors.any?
flash.now[:error] = flash[:error].to_a.concat resource.errors.full_messages
flash.now[:error].uniq!
end
end
Run Code Online (Sandbox Code Playgroud)
"app/assets/stylesheets/custom.css.scss":
.alert-error {
background-color: #f2dede;
border-color: #eed3d7;
color: #b94a48;
text-align: center; }
.alert-alert {
background-color: #f2dede; …Run Code Online (Sandbox Code Playgroud) ruby-on-rails devise twitter-bootstrap ruby-on-rails-4 twitter-bootstrap-3
devise ×3