Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
made changes to karma calculation code
Browse files Browse the repository at this point in the history
  • Loading branch information
bopanna committed Jun 7, 2013
1 parent dc4e94b commit 735fec8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class CommentsController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show, :newest]

def index
@comments = Comment.find :all, order: 'comments.created_at DESC'
@comments = Comment.find(:all, :order => 'comments.created_at DESC',:conditions => { :user_id => current_user.id }).paginate(:per_page => 10, :page => params[:page])
end

def show
Expand Down Expand Up @@ -70,7 +71,7 @@ def downvote
end

def newest
@comments = Comment.find :all, order: 'comments.created_at DESC'
@comments = Comment.find(:all, :order => 'comments.created_at DESC').paginate(:per_page => 10, :page => params[:page])
end


Expand Down
9 changes: 6 additions & 3 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
class StoriesController < ApplicationController
respond_to :html, :json
before_filter :authenticate_user!, :except => [:index, :show, :newest]

def index
@stories = Story.find :all, :order => 'total ASC'
@stories = Story.find(:all, :order => 'total DESC').paginate(:per_page => 10, :page => params[:page])
end

def show
Expand Down Expand Up @@ -89,7 +88,11 @@ def downvote
end

def newest
@stories = Story.find :all, order: 'stories.created_at DESC'
@stories = Story.find(:all, :order => 'stories.created_at DESC').paginate(:per_page => 10, :page => params[:page])
end

def user_stories
@stories = Story.find(:all, :order => 'stories.created_at DESC', :conditions => { :user_id => current_user.id }).paginate(:per_page => 10, :page => params[:page])
end

def search
Expand Down
19 changes: 7 additions & 12 deletions app/models/story.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
class Story < ActiveRecord::Base


has_many :comments
belongs_to :user
attr_accessible :title, :url, :created_at
validates_presence_of :title, :url
validates_uniqueness_of :url
attr_accessible :title, :url, :text, :created_at
validates_presence_of :title
validates_presence_of :url unless :text
validates_presence_of :text unless :url
acts_as_voteable

<<<<<<< HEAD
after_create :enqueue_create_or_update_document_job
after_destroy :enqueue_delete_document_job

=======
>>>>>>> 5008b1d5f50885a1f81197bacdb47f01b867057c
def increase_score
self.score += 1
calculate_total
save
end

def decrease_score
self.score -= 1
calculate_total
save
end

def calculate_total
time_in_seconds = Time.now - self.created_at
time_in_hours = time_in_seconds/3600
self.total = ((time_in_hours +2) ** 1.8)/self.score
self.total = (self.score/((time_in_hours +2) ** 1.8))
self.total
save
end

Expand All @@ -48,7 +46,6 @@ def url_domain

private

<<<<<<< HEAD
def enqueue_create_or_update_document_job
Delayed::Job.enqueue CreateOrUpdateSwiftypeDocumentJob.new(self.id)
end
Expand All @@ -57,6 +54,4 @@ def enqueue_delete_document_job
Delayed::Job.enqueue DeleteSwiftypeDocumentJob.new(self.id)
end

=======
>>>>>>> 5008b1d5f50885a1f81197bacdb47f01b867057c
end
10 changes: 6 additions & 4 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
<p> <%= "karma = #{@user.karma}" %><p>

<a href='/comments'>comments</a>
</h1>
<div class="sidebar round">
<p><%= "karma = #{@user.karma}" %>
<p><a href='/comments'><u>comments</u></a>
<p><a href='/userstories'><u>stories</u></a>
</div>
<div>
<%= link_to "Change Settings", edit_user_registration_path %><p>
</div>
Expand Down

0 comments on commit 735fec8

Please sign in to comment.