@ -13,6 +13,44 @@ class ForumsController < ApplicationController
include SortHelper
include SortHelper
PageLimit = 20
PageLimit = 20
def create_feedback
if User . current . logged?
@memo = Memo . new ( params [ :memo ] )
@memo . forum_id = " 1 "
@memo . author_id = User . current . id
#@forum = @memo.forum
respond_to do | format |
if @memo . save
format . html { redirect_to forum_path ( @memo . forum ) }
else
sort_init 'updated_at' , 'desc'
sort_update 'created_at' = > " #{ Memo . table_name } .created_at " ,
'replies' = > " #{ Memo . table_name } .replies_count " ,
'updated_at' = > " COALESCE (last_replies_memos.created_at, #{ Memo . table_name } .created_at) "
@topic_count = @forum . topics . count
@topic_pages = Paginator . new @topic_count , per_page_option , params [ 'page' ]
@memos = @forum . topics .
reorder ( " #{ Memo . table_name } .sticky DESC " ) .
includes ( :last_reply ) .
limit ( @topic_pages . per_page ) .
offset ( @topic_pages . offset ) .
order ( sort_clause ) .
preload ( :author , { :last_reply = > :author } ) .
all
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)
format . html { render action : :show , layout : 'base_forums' } #, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
format . json { render json : @memo . errors , status : :unprocessable_entity }
end
end
else
respond_to do | format |
format . html { redirect_to signin_path }
end
end
end
def create_memo
def create_memo
@memo = Memo . new ( params [ :memo ] )
@memo = Memo . new ( params [ :memo ] )
@ -56,9 +94,8 @@ class ForumsController < ApplicationController
@forums_count = @forums_all . count
@forums_count = @forums_all . count
@forums_pages = Paginator . new @forums_count , @limit , params [ 'page' ]
@forums_pages = Paginator . new @forums_count , @limit , params [ 'page' ]
@offset || = @forums_pages . offset
@offset || = @forums_pages . offset
@forums = @forums_all . offset ( @offset ) . limit ( @limit ) . all
@forums = @forums_all . offset ( @offset ) . limit ( @limit ) . all
#@forums = Forum.all
#@forums = Forum.all
respond_to do | format |
respond_to do | format |
format . html # index.html.erb
format . html # index.html.erb
@ -86,8 +123,6 @@ class ForumsController < ApplicationController
preload ( :author , { :last_reply = > :author } ) .
preload ( :author , { :last_reply = > :author } ) .
all
all
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forum = Forum.find(params[:id])
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics
# @memos_all = @forum.topics
@ -176,7 +211,6 @@ class ForumsController < ApplicationController
@forums_count = @forums_all . count
@forums_count = @forums_all . count
@forums_pages = Paginator . new @forums_count , @limit , params [ 'page' ]
@forums_pages = Paginator . new @forums_count , @limit , params [ 'page' ]
@offset || = @forums_pages . offset
@offset || = @forums_pages . offset
@forums = @forums_all . offset ( @offset ) . limit ( @limit ) . all
@forums = @forums_all . offset ( @offset ) . limit ( @limit ) . all
respond_to do | format |
respond_to do | format |
@ -208,17 +242,14 @@ class ForumsController < ApplicationController
end
end
end
end
private
private
def find_forum_if_available
def find_forum_if_available
@forum = Forum . find ( params [ :id ] ) if params [ :id ]
@forum = Forum . find ( params [ :id ] ) if params [ :id ]
rescue ActiveRecord :: RecordNotFound
rescue ActiveRecord :: RecordNotFound
render_404
render_404
nil
nil
end
end
def authenticate_user_edit
def authenticate_user_edit
find_forum_if_available
find_forum_if_available