把已发布的路径排在最前面
This commit is contained in:
parent
b885ad23e6
commit
eced528c8f
|
|
@ -243,8 +243,8 @@ class ShixunsController < ApplicationController
|
|||
@order = params[:order] || "myshixun_count"
|
||||
bsort = params[:sort] || "desc"
|
||||
@sort = bsort == "desc" ? "asc" : "desc"
|
||||
if @order == "created_at"
|
||||
order_str = "#{Shixun.table_name}.created_at #{bsort}"
|
||||
if @order == "updated_at"
|
||||
order_str = "#{Shixun.table_name}.updated_at #{bsort}"
|
||||
else
|
||||
order_str = "myshixun_count #{bsort}, #{Shixun.table_name}.updated_at #{bsort}"
|
||||
end
|
||||
|
|
@ -300,7 +300,7 @@ class ShixunsController < ApplicationController
|
|||
when nil, "0"
|
||||
@shixuns = @shixuns
|
||||
end
|
||||
if @order == "created_at"
|
||||
if @order == "updated_at"
|
||||
@shixuns =@shixuns.reorder(order_str)
|
||||
else
|
||||
# 最热排序
|
||||
|
|
|
|||
|
|
@ -8,12 +8,17 @@ class SubjectsController < ApplicationController
|
|||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
@order = params[:order] || "updated_at"
|
||||
bsort = params[:sort] || "asc"
|
||||
@order = params[:order] || "myshixun_count"
|
||||
bsort = params[:sort] || "desc"
|
||||
@sort = bsort == "desc" ? "asc" : "desc"
|
||||
search = params[:search]
|
||||
#ids = Subject.find_by_sql("select group_concat(id) as allId from subjects where id in (SELECT distinct(subject_id) FROM `stages`)")
|
||||
@subjects = Subject.where("hidden = 0").reorder("#{@order} #{bsort}")
|
||||
if @order == "myshixun_count"
|
||||
#@shixuns = @shixuns.select("shixuns.*, (select count(myshixuns.id) from myshixuns where myshixuns.shixun_id = shixuns.id group by shixuns.id) AS myshixunCount").reorder("status = 2 desc, myshixunCount desc")
|
||||
@subjects = Subject.where("hidden = 0").select("subjects.*, (select count(myshixuns.id) from myshixuns, stage_shixuns where myshixuns.shixun_id = stage_shixuns.shixun_id and stage_shixuns.subject_id = subjects.id group by subjects.id) AS myshixunCount").reorder("status = 2 desc, myshixunCount #{bsort}")
|
||||
else
|
||||
@subjects = Subject.where("hidden = 0").reorder("#{@order} #{bsort}")
|
||||
end
|
||||
@subject_created_count = Subject.where(:user_id => User.current.id).count
|
||||
@subjects_all_count = @subjects.count
|
||||
#@subjects = Subject.where("name like ?", "%#{search}%").reorder("#{@order} #{@sort}")
|
||||
|
|
|
|||
|
|
@ -35,6 +35,15 @@ class Subject < ActiveRecord::Base
|
|||
count
|
||||
end
|
||||
|
||||
def subject_users
|
||||
count = 0
|
||||
self.stage_shixuns.each do |stage_shixun|
|
||||
shixun = stage_shixun.shixun
|
||||
count += shixun.myshixuns.count
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def subject_score
|
||||
score = 0
|
||||
self.stage_shixuns.each do |stage_shixun|
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<ul class="nav_check_item border-bottom-orange clearfix mb15">
|
||||
<li class="fl <%= @order == 'updated_at' ? 'check_nav' : "" %>">
|
||||
<%= link_to "最热", subjects_path(:order => "updated_at", :search => @search, :sort => @sort), :remote => true %>
|
||||
<li class="fl <%= @order == 'myshixun_count' ? 'check_nav' : "" %>">
|
||||
<%= link_to "最热", subjects_path(:order => "myshixun_count", :search => @search, :sort => @sort), :remote => true %>
|
||||
</li>
|
||||
<li class="fl <%= @order == 'created_at' ? 'check_nav' : "" %>">
|
||||
<%= link_to "最新", subjects_path(:order => "created_at", :search => @search, :sort => @sort), :remote => true %>
|
||||
<li class="fl <%= @order == 'updated_at' ? 'check_nav' : "" %>">
|
||||
<%= link_to "最新", subjects_path(:order => "updated_at", :search => @search, :sort => @sort), :remote => true %>
|
||||
</li>
|
||||
<li class="fr" style="width: auto;cursor:default;">共<span class="color-orange"><%= @subjects_count %></span>个检索结果</li>
|
||||
</ul>
|
||||
|
|
@ -43,8 +43,8 @@
|
|||
<% if subject.subject_score > 0 %>
|
||||
<span class="pl5 pr5"><i class="fa fa-viacoin color-light-green pr5" aria-hidden="true" data-tip-down="总经验值"></i><em><%= subject.subject_score %></em></span>
|
||||
<% end %>
|
||||
<% if subject.subject_challenges > 0 %>
|
||||
<span class="pl5 pr5"><i class="fa fa-users color-light-green pr5" aria-hidden="true" data-tip-down="学习人数"></i><em><%= subject.subject_challenges %></em></span>
|
||||
<% if subject.subject_users > 0 %>
|
||||
<span class="pl5 pr5"><i class="fa fa-users color-light-green pr5" aria-hidden="true" data-tip-down="学习人数"></i><em><%= subject.subject_users %></em></span>
|
||||
<% end %>
|
||||
</p>
|
||||
<div class="clearfix task-index-list-user task_yx_bo" style="margin-bottom: 0px">
|
||||
|
|
|
|||
Loading…
Reference in New Issue