帖子创建不成功 给出原因

帖子发布时长度检查
This commit is contained in:
lizanle 2015-09-21 15:31:00 +08:00
parent a24ca05157
commit 553c1396dd
3 changed files with 35 additions and 44 deletions

View File

@ -7,7 +7,7 @@ class ForumsController < ApplicationController
before_filter :find_forum_if_available
before_filter :authenticate_user_edit, :only => [:edit, :update]
before_filter :authenticate_user_destroy, :only => [:destroy]
before_filter :require_login, :only => [:new, :create,:show,:destroy,:update,:edit]
before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit]
helper :sort
include SortHelper
@ -164,14 +164,7 @@ class ForumsController < ApplicationController
@memos
@my_topic_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is not null").count
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics
# @topic_count = @memos_all.count
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
# @offset ||= @topic_pages.offset
# @memos = @memos_all.offset(@offset).limit(@limit).all
@errors = params[:errors]
respond_to do |format|
format.js
format.html {

View File

@ -73,41 +73,14 @@ class MemosController < ApplicationController
end
end
#end
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
else
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
pre_count = REPLIES_PER_PAGE
@memo_new = @memo.dup
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
unless @memo.new_record?
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
end
page = params[:page]
if params[:r] && page.nil?
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
page = 1 + offset / pre_count
else
end
@reply_count = @memo.children.count
@reply_pages = Paginator.new @reply_count, pre_count, page
@replies = @memo.children.
includes(:author, :attachments).
reorder("#{Memo.table_name}.created_at DESC").
limit(@reply_pages.per_page).
offset(@reply_pages.offset).
all
if @memo.new_record?
format.html { render :new,:layout=>'base_forums'}
else
format.html { render action: :show }
format.js
format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
#end
end
end

View File

@ -1,3 +1,4 @@
<%= javascript_include_tag 'new_user' %>
<script>
function add_class(id){
if($("#"+id).hasClass("sortArrowActiveD")){
@ -47,25 +48,49 @@
$("#reorder_popu").removeClass("sortArrowActiveD");
add_class("reorder_time");
});
<% if @errors %>
$('#create_memo_div').slideToggle();$('#create_memo_btn').slideToggle();
$("#error").html('<%= @errors.html_safe %>').show();
<% end %>
});
function check_and_submit(){
if($("input[name='memo[subject]']").val().trim() != "" && $("input[name='memo[content]']").val().trim() != ""){
if($("textarea[name='memo[subject]']").val().trim() != "" && $("textarea[name='memo[content]']").val().trim() != "" && check_memo_name()){
$("#new_memo").submit();
}else{
$("#error").html("主题和内容不能为空").show();
}
}
function check_memo_name(){
if($("#memo_subject").val().trim().length > 50){
$("#error").html("主题 过长(最长为 50 个字符)").show();
return false;
}
if($("#memo_content").val().trim().length > 5000){
$("#error").html("内容 过长(最长为 5000 个字符)").show();
return false;
}
return true;
}
</script>
<div class="postRightContainer">
<div id="create_memo_div" style="display: none">
<div id="error" class="red fl mb10" style="display: none">error</div>
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %>
<div>
<input type="text" name="memo[subject]" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子标题" />
<textarea type="text" name="memo[subject]" id="memo_subject" onblur="check_memo_name();" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子标题" ></textarea>
<script>
var textarea1 = document.getElementById('memo_subject');
autoTextarea(textarea1);
</script>
</div>
<div class="mt15">
<input type="text" name="memo[content]" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入贴子内容" />
<textarea type="text" name="memo[content]" id="memo_content" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入贴子内容" /></textarea>
<script>
var textarea = document.getElementById('memo_content');
autoTextarea(textarea);
</script>
</div>
<div class="mt10">
<!--<a href="javascript:void(0);" class="AnnexBtn fl mt3">上传附件</a>-->