名称检查

This commit is contained in:
lizanle 2015-09-25 16:32:02 +08:00
parent e0c338b497
commit c3d829a68f
4 changed files with 10 additions and 7 deletions

View File

@ -296,7 +296,12 @@ class ForumsController < ApplicationController
#检查forum的名字
def check_forum_name
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false
forum_name_exist = true
if params[:forum_id]
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false
else
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false
end
render :text => forum_name_exist
end

View File

@ -54,7 +54,7 @@
$('#forum_name').keypress(function(e)
{
var n = 0;
var str = this.val().trim();
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {

View File

@ -51,9 +51,8 @@
});
$('#forum_name').keypress( function(e)
{
alert(1)
var n = 0;
var str = this.val().trim();
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {//大于255的都是中文
@ -62,7 +61,6 @@
n += 1;//英文,不多说了
}
}
console.log(n)
if(n >= 160 && e.keyCode != 8)
if(document.all)
{
@ -98,7 +96,7 @@
if( name != ""){
$.get(
'<%= check_forum_name_forums_path %>',
{"forum_name":name},
{"forum_name":encodeURIComponent(name)},
function(data){
if( data == 'true'){

View File

@ -340,7 +340,7 @@ function limitStrsize(id,length){
$('#'+id).keypress(function(e)
{
var n = 0;
var str = this.val().trim();
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {//大于255的都是中文