From 4004c4fbcc60f1110594ab2ff2f1ed080f3e13f6 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sat, 4 Feb 2012 17:03:22 -0500 Subject: [PATCH] Cleaning up rewards & showing on main page --- app/assets/images/dollar.png | Bin 0 -> 657 bytes app/assets/stylesheets/habits.css.scss | 4 +-- app/controllers/habits_controller.rb | 1 + app/controllers/rewards_controller.rb | 35 ++++++------------------- app/views/habits/index.html.erb | 10 +++++++ app/views/rewards/_form.html.erb | 8 ------ app/views/rewards/index.html.erb | 29 -------------------- app/views/rewards/show.html.erb | 25 ------------------ 8 files changed, 21 insertions(+), 91 deletions(-) create mode 100644 app/assets/images/dollar.png delete mode 100644 app/views/rewards/index.html.erb delete mode 100644 app/views/rewards/show.html.erb diff --git a/app/assets/images/dollar.png b/app/assets/images/dollar.png new file mode 100644 index 0000000000000000000000000000000000000000..e4df25001f725cdac943f39757b336f44d5ead2d GIT binary patch literal 657 zcmV;C0&e|@P)ADUY6VJ|LP23}3%sfVLrAgd6_vEk0 z*-SJ|Yh8TG<#aRAPBa&3XcP8kBG-vp z6z}GibCA_KP7hr`VB5eQMOIb9-6jYUP@S~_*^OcUMgvgrB53%MwiId3xXFRW41yd`%_#dVDwM*S3-2}?tKsJ zHaqgmSx9vO9`^ynYOqrz7I-?0`SuHMqr839_Wjm_6~_(!gxxhZH0a3BSdpw|A4lk(>@A rR*kgwF*PGacVp-Bt 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) + @rewards = current_user.rewards respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/rewards_controller.rb b/app/controllers/rewards_controller.rb index 1a30f9064a..a655408846 100644 --- a/app/controllers/rewards_controller.rb +++ b/app/controllers/rewards_controller.rb @@ -1,30 +1,10 @@ class RewardsController < ApplicationController - # GET /rewards - # GET /rewards.json - def index - @rewards = Reward.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @rewards } - end - end - - # GET /rewards/1 - # GET /rewards/1.json - def show - @reward = Reward.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @reward } - end - end # GET /rewards/new # GET /rewards/new.json def new @reward = Reward.new + @reward.user_id = current_user.id respond_to do |format| format.html # new.html.erb @@ -34,17 +14,18 @@ class RewardsController < ApplicationController # GET /rewards/1/edit def edit - @reward = Reward.find(params[:id]) + @reward.user_id = current_user.id end # POST /rewards # POST /rewards.json def create @reward = Reward.new(params[:reward]) + @reward.user_id = current_user.id respond_to do |format| if @reward.save - format.html { redirect_to @reward, notice: 'Reward was successfully created.' } + format.html { redirect_to habits_url, notice: 'Reward was successfully created.' } format.json { render json: @reward, status: :created, location: @reward } else format.html { render action: "new" } @@ -56,11 +37,11 @@ class RewardsController < ApplicationController # PUT /rewards/1 # PUT /rewards/1.json def update - @reward = Reward.find(params[:id]) + @reward = curren_user.rewards.find(params[:id]) respond_to do |format| if @reward.update_attributes(params[:reward]) - format.html { redirect_to @reward, notice: 'Reward was successfully updated.' } + format.html { redirect_to habits_url, notice: 'Reward was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } @@ -72,11 +53,11 @@ class RewardsController < ApplicationController # DELETE /rewards/1 # DELETE /rewards/1.json def destroy - @reward = Reward.find(params[:id]) + @reward = current_user.reward.find(params[:id]) @reward.destroy respond_to do |format| - format.html { redirect_to rewards_url } + format.html { redirect_to habits_url } format.json { head :no_content } end end diff --git a/app/views/habits/index.html.erb b/app/views/habits/index.html.erb index ae675e63c1..f896a354a3 100644 --- a/app/views/habits/index.html.erb +++ b/app/views/habits/index.html.erb @@ -55,9 +55,19 @@ <%= render 'money'%>
+ <% @rewards.each do |reward| %> +
  • + <%= link_to(image_tag('dollar.png'), { :controller=>"reward", :action => "buy", :id => reward.id }, :remote=>true) %> + <%= reward.name %> +
    + <%= link_to 'Edit', edit_reward_path(reward) %> +
    +
  • + <% end %>
    + <%= link_to 'New Reward', new_reward_path %> diff --git a/app/views/rewards/_form.html.erb b/app/views/rewards/_form.html.erb index ff60f9283a..3a03ec063f 100644 --- a/app/views/rewards/_form.html.erb +++ b/app/views/rewards/_form.html.erb @@ -19,14 +19,6 @@ <%= f.label :value %>
    <%= f.number_field :value %> -
    - <%= f.label :position %>
    - <%= f.number_field :position %> -
    -
    - <%= f.label :user_id %>
    - <%= f.number_field :user_id %> -
    <%= f.submit %>
    diff --git a/app/views/rewards/index.html.erb b/app/views/rewards/index.html.erb deleted file mode 100644 index 0128a2f284..0000000000 --- a/app/views/rewards/index.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -

    Listing rewards

    - - - - - - - - - - - - -<% @rewards.each do |reward| %> - - - - - - - - - -<% end %> -
    NameValuePositionUser
    <%= reward.name %><%= reward.value %><%= reward.position %><%= reward.user_id %><%= link_to 'Show', reward %><%= link_to 'Edit', edit_reward_path(reward) %><%= link_to 'Destroy', reward, confirm: 'Are you sure?', method: :delete %>
    - -
    - -<%= link_to 'New Reward', new_reward_path %> diff --git a/app/views/rewards/show.html.erb b/app/views/rewards/show.html.erb deleted file mode 100644 index d902a11661..0000000000 --- a/app/views/rewards/show.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -

    <%= notice %>

    - -

    - Name: - <%= @reward.name %> -

    - -

    - Value: - <%= @reward.value %> -

    - -

    - Position: - <%= @reward.position %> -

    - -

    - User: - <%= @reward.user_id %> -

    - - -<%= link_to 'Edit', edit_reward_path(@reward) %> | -<%= link_to 'Back', rewards_path %>