处理贴吧同名问题
This commit is contained in:
parent
6fcf80cd3c
commit
bef4e7be12
|
@ -340,7 +340,11 @@ class ForumsController < ApplicationController
|
|||
def check_forum_name
|
||||
begin
|
||||
forum_name = params[:forum_name]
|
||||
result = Forum.find_by_name(forum_name).blank? ? {:result => true} : {:result => false}
|
||||
if params[:forum_id]
|
||||
result = Forum.where("name = '#{forum_name}' and id != #{params[:forum_id]}").first.blank? ? {:result => true} : {:result => false}
|
||||
else
|
||||
result = Forum.where(:name => forum_name).first.blank? ? {:result => true} : {:result => false}
|
||||
end
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
|
|
|
@ -5,48 +5,8 @@
|
|||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="muban_popup_con mt15" >
|
||||
<%= labelled_form_for @forum, :html => {:id => "forum_new", :remote => true} do |f| %>
|
||||
<%= labelled_form_for @forum, :forum_id => @forum.id, :html => {:id => "forum_new", :remote => true} do |f| %>
|
||||
<%= render :partial => "forums/form", :locals => {:f => f} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function forums_commit(){
|
||||
$("#forum_name_error_tips").hide();
|
||||
$("#forum_description_error_tips").hide();
|
||||
if ($("#forum_name").val().trim() == ""){
|
||||
$("#forum_name_error_tips").html("贴吧名称不能为空").show();
|
||||
}
|
||||
else if($("#forum_desc").val().trim() == ""){
|
||||
$("#forum_description_error_tips").html("贴吧描述不能为空").show();
|
||||
}
|
||||
else if($("#forum_desc").val().length > 5000){
|
||||
$("#forum_description_error_tips").html("贴吧描述不能超过5000个字符").show();
|
||||
}
|
||||
else{
|
||||
$.ajax({
|
||||
url:'<%= check_forum_name_forums_path %>',
|
||||
type:'get',
|
||||
data:{
|
||||
forum_name:$("#forum_name").val().trim()
|
||||
},
|
||||
success:function(data){
|
||||
if(data.result == true){
|
||||
alert("提交成功");
|
||||
$("#forum_new").submit();
|
||||
hideModal();
|
||||
return true;
|
||||
}else{
|
||||
alert("提交失败");
|
||||
$("#forum_name_error_tips").html("贴吧名称已存在").show();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
alert('请检查当前网络连接')
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -46,7 +46,7 @@
|
|||
}
|
||||
else{
|
||||
$.ajax({
|
||||
url:'<%= check_forum_name_forums_path %>',
|
||||
url:'<%= check_forum_name_forums_path(:forum_id => @forum.try(:id)) %>',
|
||||
type:'get',
|
||||
data:{
|
||||
forum_name:$("#forum_name").val().trim()
|
||||
|
|
Loading…
Reference in New Issue