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.5 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if topic[:infocount] < 0
  23. topic[:infocount] = 0
  24. end
  25. end
  26. @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
  27. @topics = sort_by_sticky @topics
  28. @topics = sortby_time_countcommon_hassticky @topics,sort_name
  29. else
  30. @type = 1
  31. end
  32. #分页
  33. @limit = 10
  34. @is_remote = true
  35. @atta_count = @topics.count
  36. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  37. @offset ||= @atta_pages.offset
  38. @topics = paginateHelper @topics,@limit
  39. respond_to do |format|
  40. format.js
  41. format.html {render :layout=>'new_base_user'}
  42. end
  43. end
  44. def create
  45. end
  46. def new
  47. end
  48. def show
  49. end
  50. def update
  51. end
  52. def destory
  53. end
  54. def edit
  55. end
  56. def set_homepage
  57. @blog = Blog.find(params[:id])
  58. @blog.update_attribute(:homepage_id, params[:article_id])
  59. redirect_to user_path(params[:user_id])
  60. end
  61. def cancel_homepage
  62. @blog = Blog.find(params[:id])
  63. @blog.update_attribute(:homepage_id, nil)
  64. redirect_to user_blogs_path(params[:user_id])
  65. end
  66. private
  67. def find_blog
  68. if params[:blog_id]
  69. @blog = Blog.find(params[:blog_id])
  70. else
  71. render_404
  72. end
  73. if @blog.nil?
  74. #如果某个user的blog不存在,那么就创建一条
  75. @blog = Blog.create(:name=>User.find(params[:id]).realname ,
  76. :description=>'',
  77. :author_id=>params[:id])
  78. end
  79. end
  80. def find_user
  81. @user = User.find(params[:user_id])
  82. end
  83. end

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