Refactore progressbar via score in application_helper

This commit is contained in:
Tyler Renelle
2012-02-04 16:39:56 -05:00
parent 88e105a442
commit 3abcf468e9
6 changed files with 8 additions and 15 deletions

View File

@@ -8,7 +8,6 @@ class HabitsController < ApplicationController
@habits = current_user.habits.where(:habit_type => Habit::ALWAYS)
@daily = current_user.habits.where(:habit_type => Habit::DAILY)
@one_time = current_user.habits.where(:habit_type => Habit::ONE_TIME).where(:done=>false)
@score = current_user.habits.sum('score').to_i
respond_to do |format|
format.html # index.html.erb
@@ -98,7 +97,6 @@ class HabitsController < ApplicationController
@habit.user=current_user
@habit.vote(params[:vote])
@score = current_user.habits.sum('score').to_i
respond_to do |format|
# format.html { render action: "edit" }

View File

@@ -1,2 +1,6 @@
module ApplicationHelper
def score
current_user.habits.sum('score').to_i
end
end

View File

@@ -1,9 +1,4 @@
<% content_for :score do %>
<%= render :partial => "progressbar", :locals => { :score => @score } %>
<% end %>
<%= link_to 'New Habit', new_habit_path %>
<%= link_to 'Back', habits_url %>
<table id="layout">
<tr>

View File

@@ -1,8 +1,3 @@
<% content_for :score do %>
<%= render :partial => "progressbar", :locals => { :score => @score } %>
<% end %>
<%= link_to 'New Habit', new_habit_path %>
<table id="layout">
@@ -50,6 +45,7 @@
</div>
</div>
</div>
<%= link_to 'View Completed', :action=>'completed' %>
</td>
<td class="panel">

View File

@@ -1,5 +1,5 @@
<% unless @habit.habit_type==Habit::ONE_TIME %>
$('#habit_<%= @habit.id %>').replaceWith("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>");
<% end %>
$('#progressbar').replaceWith("<%= escape_javascript(render :partial => "progressbar", :locals => { :score => @score }) %>");
$('#progressbar').replaceWith("<%= escape_javascript(render :partial => "progressbar") %>");
$('#money').replaceWith("<%= escape_javascript(render 'money') %>");

View File

@@ -10,7 +10,7 @@
<div id="container">
<div id="header">
<!-- <h1><a href="/">Web App</a></h1> -->
<%= yield :score %>
<%= render :partial => "progressbar" %>
<div id="user-navigation">
<ul class="wat-cf">
<li><a href="#"><%= t("web-app-theme.profile", :default => "Profile") %></a></li>