Skip to content

Commit

Permalink
Paginating top solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
David Davis committed Feb 25, 2012
1 parent fc95549 commit 6a0701f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
15 changes: 10 additions & 5 deletions app/assets/stylesheets/application.css.scss
Expand Up @@ -427,12 +427,15 @@ div#flash {
nav.pagination {
margin: 1em 0 0;
float: right;
span.current {
span, a {
display: block;
float: left;
float: left; }
span.gap {
margin-right: 4px;
padding: 4px 2px; }
span.current {
font-weight: bold;
border: 1px solid #333;
background: #666;
margin: 0 4px 0 0px;
color: #fff;
background: #c6c6c6 url(Aristo/bg_fallback.png) 0 0 repeat-x; /* Old browsers */
Expand All @@ -444,8 +447,6 @@ nav.pagination {
background: linear-gradient(top, #c6c6c6 0%,#e6e6e6 100%); /* W3C */
padding: 4px 6px; }
a {
display: block;
float: left;
text-decoration: none;
padding: 4px 6px;
margin: 0 4px 0 0px;
Expand Down Expand Up @@ -516,3 +517,7 @@ div.links {
line-height: 27px;
text-shadow: 0 1px #fff;
}

.solutions .pagination {
margin: 0px;
}
5 changes: 2 additions & 3 deletions app/controllers/solutions_controller.rb
Expand Up @@ -8,9 +8,8 @@ def index
if !current_user_admin? && (@problem.nil? || !@problem.solved?(current_user))
redirect_to @problem and return
end
@top_solutions = Solution.all(conditions: { problem_id: @problem.id, user_id: { "$nin" => [current_user.id] } },
sort: [[:score, :desc], [:updated_at, :desc]],
limit: 5)
@top_solutions = Solution.where(problem_id: @problem.id, user_id: { "$nin" => [current_user.id] }).
desc(:score).desc(:updated_at).page(params[:page] || 1)
@followed_users = current_user.users_followed.reject{|u| u.solutions.where(problem_id: @problem.id).empty?}

respond_to do |format|
Expand Down
2 changes: 2 additions & 0 deletions app/models/solution.rb
Expand Up @@ -19,6 +19,8 @@ class Solution
after_destroy :update_user_solution_count
validates_presence_of :problem_id

paginates_per 5

track_history :track_create => true,
:track_destroy => true

Expand Down
3 changes: 3 additions & 0 deletions app/views/solutions/index.html.erb
Expand Up @@ -27,7 +27,10 @@
</div>

<% end -%>
<%= paginate @top_solutions %>
</div>
<div class="clear"></div>

<% if solution = Solution.first(conditions: { user_id: current_user.id, problem_id: @problem.id }) %>
<hr/>
Expand Down

0 comments on commit 6a0701f

Please sign in to comment.