diff --git a/app/controllers/habits_controller.rb b/app/controllers/habits_controller.rb index 86f693a520..fa83c1998a 100644 --- a/app/controllers/habits_controller.rb +++ b/app/controllers/habits_controller.rb @@ -6,7 +6,8 @@ class HabitsController < ApplicationController # GET /habits.json def index @habits = current_user.habits.where(:habit_type => Habit::ALWAYS) - @todos = current_user.habits.where(:habit_type => Habit::DAILY) + @daily = current_user.habits.where(:habit_type => Habit::DAILY) + @score = current_user.habits.sum('score') respond_to do |format| format.html # index.html.erb @@ -80,6 +81,7 @@ class HabitsController < ApplicationController def vote @habit = current_user.habits.find(params[:id]) @habit.vote(params[:vote]) + @score = current_user.habits.sum('score') respond_to do |format| if @habit.save diff --git a/app/views/habits/index.html.erb b/app/views/habits/index.html.erb index 30453531d2..6c8b44fbe0 100644 --- a/app/views/habits/index.html.erb +++ b/app/views/habits/index.html.erb @@ -1,4 +1,4 @@ - +

Score: <%= @score %>

<%= link_to 'New Habit', new_habit_path %> @@ -17,7 +17,7 @@

Daily

diff --git a/app/views/habits/vote.js.erb b/app/views/habits/vote.js.erb index 38b61ac6ef..74720e9b36 100644 --- a/app/views/habits/vote.js.erb +++ b/app/views/habits/vote.js.erb @@ -1 +1,2 @@ -$('#<%= @habit.id %>').html("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>") +$('#<%= @habit.id %>').html("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>"); +$('#score').html("<%= @score %>");