mtc*_*s70 5 ruby flash ruby-on-rails devise ruby-on-rails-3
尝试使 Devise 在错误注册时生成闪存错误消息。例如“电子邮件不能为空”或“密码太短”。
在查看 Railscast 第 210 集时,这似乎是 Devise 的开箱即用功能(通过 validatable),但在我的实例中,没有生成用于注册的 Flash 消息。请注意,闪现消息确实会在此应用程序的其他实例中生成,例如发送重置指令、删除帐户等...(如果您想亲自查看,可以在生产网站 ninjaspeak.com 上查看该行为)
对于为什么会这样有什么想法吗?
将 Devise 2.1.2 与 Rails 3.2.13 结合使用
devise.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'
Run Code Online (Sandbox Code Playgroud)
application.html.erb:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, id: "flash_#{name}" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
用户.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
Run Code Online (Sandbox Code Playgroud)
编辑以显示CSS:
#flash_alert {
padding-top: 16px;
float: right;
}
#flash_notice {
padding-top: 16px;
float: right;
}
Run Code Online (Sandbox Code Playgroud)
问题出在我的views/devise/registrations/new.html.erb 文件上。
下
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
我必须添加设计错误消息助手:
<%= devise_error_messages! %>
Run Code Online (Sandbox Code Playgroud)
现在,无效注册时会出现闪现消息,例如“电子邮件不能为空”、“密码与确认不匹配”等...
| 归档时间: |
|
| 查看次数: |
3848 次 |
| 最近记录: |