You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

blogs_controller.rb 2.6 kB

10 years ago
​
​
10 years ago
​
​
10 years ago
10 years ago
10 years ago
10 years ago
​
​
10 years ago
​
​
​
​
10 years ago
​
​
​
10 years ago
​
​
10 years ago
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. class BlogsController < ApplicationController
  2. before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
  3. before_filter :find_user
  4. include PraiseTreadHelper
  5. def index
  6. @article = BlogComment.new
  7. @order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
  8. #确定 sort_type 1升序 2 降序
  9. if @order.to_i == @type.to_i
  10. @b_sort = @b_sort.to_i == 1 ? 2 : 1
  11. else
  12. @b_sort = 2
  13. end
  14. sort_name = "updated_at"
  15. sort_type = @b_sort == 1 ? "asc" : "desc"
  16. @topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{sort_type}")
  17. #根据 赞+回复数排序
  18. if @order.to_i == 2
  19. @type = 2
  20. @topics.each do |topic|
  21. # topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
  22. topic[:infocount] = get_praise_num(topic) + ReplyCache.blog_replys_cache(topic.id).count
  23. if topic[:infocount] < 0
  24. topic[:infocount] = 0
  25. end
  26. end
  27. @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
  28. @topics = sort_by_sticky @topics
  29. @topics = sortby_time_countcommon_hassticky @topics,sort_name
  30. else
  31. @type = 1
  32. end
  33. #分页
  34. @limit = 10
  35. @is_remote = true
  36. @atta_count = @topics.count
  37. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  38. @offset ||= @atta_pages.offset
  39. @topics = paginateHelper @topics,@limit
  40. respond_to do |format|
  41. format.js
  42. format.html {render :layout=>'new_base_user'}
  43. end
  44. end
  45. def create
  46. end
  47. def new
  48. end
  49. def show
  50. end
  51. def update
  52. end
  53. def destory
  54. end
  55. def edit
  56. end
  57. def set_homepage
  58. @blog = Blog.find(params[:id])
  59. @blog.update_attribute(:homepage_id, params[:article_id])
  60. redirect_to user_path(params[:user_id])
  61. end
  62. def cancel_homepage
  63. @blog = Blog.find(params[:id])
  64. @blog.update_attribute(:homepage_id, nil)
  65. redirect_to user_blogs_path(params[:user_id])
  66. end
  67. private
  68. def find_blog
  69. if params[:blog_id]
  70. @blog = Blog.find(params[:blog_id])
  71. else
  72. render_404
  73. end
  74. if @blog.nil?
  75. #如果某个user的blog不存在,那么就创建一条
  76. @blog = Blog.create(:name=>User.find(params[:id]).realname ,
  77. :description=>'',
  78. :author_id=>params[:id])
  79. end
  80. end
  81. def find_user
  82. @user = User.find(params[:user_id])
  83. end
  84. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...