Purchasing now works, refactored money to shared

This commit is contained in:
Tyler Renelle 2012-02-04 17:14:39 -05:00
parent ba110c7857
commit 82a343fa71
5 changed files with 20 additions and 4 deletions

View file

@ -61,4 +61,19 @@ class RewardsController < ApplicationController
format.json { head :no_content }
end
end
def buy
@reward = current_user.rewards.find(params[:id])
current_user.money -= @reward.value
current_user.save
respond_to do |format|
# format.html { render action: "edit" }
# format.json { render json: @habit.errors, status: :unprocessable_entity }
format.js
end
end
end

View file

@ -52,12 +52,12 @@
<div class="block">
<div class='content'>
<h2 class='title'>Rewards
<%= render 'money'%>
<%= render 'shared/money'%>
</h2>
<div class='inner'>
<% @rewards.each do |reward| %>
<li id="reward_<%= reward.id %>" class="reward">
<%= link_to(image_tag('dollar.png'), { :controller=>"reward", :action => "buy", :id => reward.id }, :remote=>true) %>
<%= link_to(image_tag('dollar.png'), { :controller=>"rewards", :action => "buy", :id => reward.id }, :remote=>true) %>
<%= reward.name %>
<div class='edit'>
<%= link_to 'Edit', edit_reward_path(reward) %>

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") %>");
$('#money').replaceWith("<%= escape_javascript(render 'money') %>");
$('#progressbar').replaceWith("<%= escape_javascript(render :partial => "shared/progressbar") %>");
$('#money').replaceWith("<%= escape_javascript(render 'shared/money') %>");

View file

@ -0,0 +1 @@
$('#money').replaceWith("<%= escape_javascript(render 'shared/money') %>");