diff --git a/app/controllers/habits_controller.rb b/app/controllers/habits_controller.rb index 7160a23748..090c774ded 100644 --- a/app/controllers/habits_controller.rb +++ b/app/controllers/habits_controller.rb @@ -78,9 +78,8 @@ class HabitsController < ApplicationController def vote @habit = current_user.habits.find(params[:id]) - @habit.score += params[:vote].to_i - @habit.votedate = Time.now - + @habit.vote(params[:vote]) + respond_to do |format| if @habit.save # format.html { redirect_to @habit, notice: 'Habit was successfully updated.' } diff --git a/app/models/habit.rb b/app/models/habit.rb index 4fbed23103..9b662e364c 100644 --- a/app/models/habit.rb +++ b/app/models/habit.rb @@ -5,7 +5,11 @@ class Habit < ActiveRecord::Base belongs_to :user - def next_vote - 1 #TODO return log or linear based on current score + def vote(direction) + next_vote = 1 #TODO return log or linear based on current score + next_vote *= -1 if(direction=='down') + self.score += next_vote + self.votedate = Time.now + #TODO if type=daily & votedate=today, set done back to false (have a done column?) end end diff --git a/app/views/habits/_habit.html.erb b/app/views/habits/_habit.html.erb index 9a6282f4ef..c06b4f14c2 100644 --- a/app/views/habits/_habit.html.erb +++ b/app/views/habits/_habit.html.erb @@ -1,8 +1,8 @@
<%= habit.name %> (<%= habit.score %>) - <%= link_to "√", { :action => "vote", :id => habit.id, :vote => habit.next_vote }, :remote=>true %> - <%= link_to "X", { :action => "vote", :id => habit.id, :vote => -(habit.next_vote) }, :remote=>true %> + <%= link_to "√", { :action => "vote", :id => habit.id, :vote => 'up' }, :remote=>true %> + <%= link_to "X", { :action => "vote", :id => habit.id, :vote => 'down' }, :remote=>true %> <%= link_to 'Edit', edit_habit_path(habit) %>