socialforge/app/controllers/homepages_controller.rb

64 lines
2.1 KiB
Ruby
Raw Normal View History

2016-10-19 18:03:59 +08:00
class HomepagesController < ApplicationController
before_filter :find_user
def index
if User.current.logged? && User.current == @user
@b_sort = params[:sort] || 1
@b_sort = @b_sort.to_i == 1 ? 2 : 1
sort_type = @b_sort == 1 ? "asc" : "desc"
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at #{sort_type}")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at #{sort_type}").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
2016-10-19 18:03:59 +08:00
@limit = 20
@is_remote = true
@atta_count = @articles.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
@articles = paginateHelper @articles,@limit
respond_to do |format|
format.js
format.html {render :layout=>'new_base_user'}
end
else
render_403
end
end
def show
end
def set_homepage
@homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, params[:article_id])
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
2016-10-19 20:33:39 +08:00
redirect_to user_homepages_path(:user_id => @user.id)
2016-10-19 18:03:59 +08:00
end
def cancel_homepage
@homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, nil)
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
2016-10-19 20:33:39 +08:00
redirect_to user_homepages_path(:user_id => @user.id)
2016-10-19 18:03:59 +08:00
end
private
def find_user
@user = User.find(params[:user_id])
end
end