- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
尝试使 Devise 在不正确的注册时生成 flash 错误消息。例如“电子邮件不能为空”或“密码太短”。
在查看 railscast episode 210 时,这似乎是 Devise 开箱即用的功能(通过可验证),但在我的实例中,没有生成用于注册的闪存消息。请注意,此应用程序的其他实例中会生成闪现消息,例如发送重置指令、删除帐户等...(如果您想亲自查看,可以在生产网站 ninjaspeak.com 上查看行为)
对为什么会这样有任何想法吗?
将 Devise 2.1.2 与 Rails 3.2.13 结合使用
设计.en.yml:
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: ''
signed_out: ''
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your NinjaSpeak account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your NinjaSpeak account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Your NinjaSpeak account was successfully cancelled.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'
应用程序.html.erb:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, id: "flash_#{name}" %>
<% end %>
用户.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable and :activatable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :natives_language, :next_language, :remember_me, :bookmark
# attr_accessible :title, :body
validates_presence_of :natives_language, :next_language
end
编辑以显示 css:
#flash_alert {
padding-top: 16px;
float: right;
}
#flash_notice {
padding-top: 16px;
float: right;
}
最佳答案
据我所知,devise 不会管理验证错误,这就是为什么你不能这样做,而且以我的拙见,我认为这不是一个好的行为。所以我建议您使用正常显示来显示验证错误。
如果您想改进验证消息以在客户端验证它们,而无需到达服务器,您可以使用“jquery-validation-rails”并添加到 application.js 或其他 javascript 文件,如下所示:
//validador jquery
$('#new_user').validate({
rules: {
'user[password]': {
required: true,
maxlength: 100
},
'user[email]': {
required: true,
email: true,
maxlength: 150
}
},
messages: {
'user[password]': {
required: "Required Field",
maxlength: "Name too big, max size 100"
},
'user[email]': {
required: "Required Field",
email: "Invalid email",
maxlength: "Email too big, max size 150"
}
}
});
如果你想改变错误信息的颜色你可以用css来做
/* Change color to error messages for validation with jQuery */
label.error{
color: white !important;
font-weight: normal !important;
}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :password,
presence: true,
length: { maximum: 100 }
validates :email,
presence: true,
length: { maximum: 150 },
format: { with: VALID_EMAIL_REGEX }
我喜欢用这种方式在 rails 中捕获 flash 消息,它在右侧有一个“X”按钮和“关闭”文本,使其更具用户体验。
<!-- Flash Notice for Rails notifications -->
<% if notice %>
<p class="alert alert-success">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only" style="font-size: 14px !important;"> Close</span></button>
<%= notice %>
</p>
<% end %>
<% if alert %>
<p class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only" style="font-size: 14px !important;"> Close</span></button>
<%= alert %>
</p>
<% end %>
此外,您还可以在 Rails 3 或 4.1 中使用名为“growlyflash”的 gem,它可以使用粗暴的消息样式来闪烁消息,并使其看起来很酷。如果你使用 growlyflash,你不需要 flash 消息的代码,而是你将在你的“application.html.erb”中使用它:
<%= growlyflash_static_notices %>
如果你想让消息在点击时消失,只需要在一个名为“growlyflash.js”的文件中添加这个javascript(只是为了保持代码的组织性)。我还添加了一种方法来解决危险消息颜色的问题。
// The message will disappear when get clicked
jQuery(function() {
$(document).on('click.alert.data-api', '[data-dismiss="alert"]', function(e) {
return e.stopPropagation();
});
return $(document).on('touchstart click', ".bootstrap-growl", function(e) {
e.stopPropagation();
$('[data-dismiss="alert"]', this).click();
return false;
});
});
// This part of code is VERY IMPORTANT, because it solved an issue for rendering color
// to the danger message.
$.bootstrapGrowl.defaults = $.extend(true, {}, $.bootstrapGrowl.defaults, {
type_mapping: {
alert: 'warning',
error: 'danger',
notice: 'info',
success: 'success'
}
});
希望对你有帮助:D
关于ruby-on-rails - Rails/Device 注册不正确时不会生成 Flash 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27582232/
我在 mac 上,我有一个预先存在的 Flash 项目。 (即通常的 fla、src、lib)文件夹。 现在,我想开始使用 Flash Builder 4 编写代码。 如何导入所有这些文件,以便我现在
我在 Flash 视频播放器中遇到了一个奇怪的、很难重现的图形故障!,目前仅在 Chrome 中。 “进入建筑物”下方的灰色矩形显示了 Flash 播放器所在的 html div 的背景颜色。“我们在
我对 Flash 有点陌生,我只是找不到一种很好的方法来控制我添加到容器影片剪辑中的元素的位置。 我所做的是 addChild 到我的目标容器 Movie Clip 和控件 child 的 x,y 值
我是一名 AS3 开发人员,习惯于使用 Flash Builder。我正在与一位使用 Flash Professional 为游戏设计 Sprite 和背景的设计师合作。我希望为我们创建一个集成的工作
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
当您像下面那样在 FLash Builder 中嵌入媒体时,它会创建一个类来引用 [Embed(source="images/list.png")] protected static const LI
有没有办法在 Flash 上本地启用跳帧? 当您开发游戏时,您会开发动画以匹配游戏玩法的节奏,并以目标帧速率(Flash 通常为 24-40fps)进行制作。但是如果用户的电脑速度太慢,无法保持目标帧
大家好,我想知道 AS3 中的 dispatchEvent 是什么。 谷歌搜索时没有任何想法。 :( 所以请帮帮我 编辑1: public static const SET_VOLUME:Strin
我多次听说我应该避免在我的网站上使用 Flash。然而,没有人告诉我这样做的充分理由。我已经搜索了原因,我看到很多不正确的(例如 Flash 中的文本不能被搜索引擎索引),或者不一定是真实的或足够重要
我正在为一个非常大的网站做一些测试,创建了许多不同的开发人员。有没有办法判断网站是否在使用 flash和/或已加载闪存 plugin ?如果页面使用 Flash,有没有办法告诉页面/代码的哪一部分触发
我正在研究“Foundation Actionscript 3.0”一书中的音频播放器演示。当我尝试发布 AudioDemo_final.FLA 文件时,出现以下错误:“Adobe Flash CS3
我有一个特定的FLA,每次尝试编译时都会崩溃(切换到Snow Leopard之后)。 Flash只是停滞不前,我被迫使用“强制退出” ...我不知道是什么原因造成的,并且找不到任何崩溃报告。 Flas
所以我非常熟悉 Java、C 和 C++ 中的内存管理;然而,在闪存中有哪些结构用于内存管理?我假设 flash 有一种像 java 的虚拟机,并且我一直假设当它们被设置为 null 时会被垃圾收集。
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 5年前关闭。 Improve thi
是否可以在 flash 中创建 UDP 套接字连接?我知道 RTMPF,但它不提供对 UDP 的访问。我知道在 AIR 中它是可能的,但我正在寻找一种“闪光”解决方案。 谢谢你 最佳答案 号 UDP
不知道如何表达这个意思,但是我想知道是否可以创建一个全面的错误处理程序来保护整个代码,然后发送给自定义处理程序,该程序在程序中以图形方式输出信息。类似于以下内容: root.addEventListe
我正在尝试创建可在不同场景中使用的UI影片剪辑。 它使用来自根范围的变量来确定状态。 当我按下静音按钮时,效果很好,但是当我尝试取消静音时,就变得很奇怪。有时需要2次点击才能取消静音,有时还需要更多。
是否可以通过麦克风记录最终用户? 我可以用录音做什么 Action ? 例如,我能否实时获得声音(分贝)的音量? 我可以将记录保存到文件中吗? 谢谢。 最佳答案 是的,Flash允许(具有用户许可权)
当我访问我之前在 IE 中构建的站点时,我在浏览器底部弹出消息栏,提示该站点想要运行 Flash。 这很好,除了网站中没有任何 Flash。 什么会导致这种情况? Flash 现在怎么会出现在站点中?
概要 我正在尝试制作一个包含多个相同SWF的网页。我有一个问题,它的加载速度太慢了(虽然下载时间还不错)。我在每个单元格中都有一个4x4表格,在iframe中嵌入了一个swf文件。 (注意:4 X 4
我是一名优秀的程序员,十分优秀!