部分sql语句写成rails形式

This commit is contained in:
yanxd 2013-12-16 19:08:00 +08:00
parent 4f9686fc57
commit 246ab25bf0
2 changed files with 10 additions and 9 deletions

View File

@ -159,11 +159,12 @@ module WelcomeHelper
end
def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=15
Project.find_by_sql("
SELECT p.id, p.name, p.description, p.identifier, t.project_id
FROM projects AS p RIGHT OUTER JOIN (
SELECT project_id,grade FROM project_statuses
WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
# Project.find_by_sql("
# SELECT p.id, p.name, p.description, p.identifier, t.project_id
# FROM projects AS p RIGHT OUTER JOIN (
# SELECT project_id,grade FROM project_statuses
# WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
Project.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all
end
def sort_bid_by_hot_rails reward_type, limit = 10

View File

@ -292,13 +292,13 @@
</div>
<div style="float: left; margin-left: 10px; width: 360px;">
<p class="layout">
<span style="display: inline-block; width: 250px;"><%= link_to( project.name, project_path(project.project_id), :class => "d-g-blue d-p-project-name", :title => "#{project.name}")%></span>
<!-- <span style="cursor: help; display: inline-block; float: right; color: #ec6300; background: url('/images/score.png') no-repeat scroll ;background-position: left center;" title="项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度" class="tooltip-#{project.project_id}"><%= show_grade project %></span> -->
<span style="display: inline-block; width: 250px;"><%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name", :title => "#{project.name}")%></span>
<!-- <span style="cursor: help; display: inline-block; float: right; color: #ec6300; background: url('/images/score.png') no-repeat scroll ;background-position: left center;" title="项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度" class="tooltip-#{project.id}"><%= show_grade project %></span> -->
<%= content_tag "span", show_grade(project),
:style => "cursor: pointer; display: inline-block; float: right; color: #ec6300; ",
:title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度",
:class => "tooltip",
:id => "tooltip-#{project.project_id}" %>
:id => "tooltip-#{project.id}" %>
</p>
<p class="layout-1" >
<%= content_tag "span", project.description.truncate(50, omission: '...'), :class => "d-p-project-intro" , :title => project.description %>
@ -326,7 +326,7 @@
</div>
<div style="float: left; margin-left: 10px; width: 360px;">
<p class="layout">
<%= link_to( project.name, project_path(project.project_id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}")%>
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}")%>
<span style="cursor: pointer; display: inline-block; float: right; color: #ec6300; white-space: nowrap;">学生人数:<%= link_to "#{studentCount(project)}", project_member_path(project, :role => 2) ,:course =>'1'%></span>
</p>
<p class="layout-1" >