, devise , , . .
, ,
" jquery-validation-rails" application.js javascript :
validation_jquery.js
$('#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
validation_jquery.css
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
- , "X" "", UX.
<% 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 %>
Super Cool Growlyflash
, Rails 3 4.1 , " growlyflash", -, . growlyflash, -, "application.html.erb":
<%= growlyflash_static_notices %>
, , javascript "growlyflash.js" ( ). .
Growlyflash.js
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;
});
});
$.bootstrapGrowl.defaults = $.extend(true, {}, $.bootstrapGrowl.defaults, {
type_mapping: {
alert: 'warning',
error: 'danger',
notice: 'info',
success: 'success'
}
});
, : D