Cleaning up rewards & showing on main page

This commit is contained in:
Tyler Renelle 2012-02-04 17:03:22 -05:00
parent dd96bfee83
commit 4004c4fbcc
8 changed files with 21 additions and 91 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

View file

@ -21,7 +21,7 @@
margin-left:0px;
}
.habit {
.habit, .reward {
list-style:none;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
@ -32,7 +32,7 @@
text-shadow:none;
}
.habit:hover {
.habit:hover, .reward:hover {
cursor: move;
}

View file

@ -8,6 +8,7 @@ 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)
@rewards = current_user.rewards
respond_to do |format|
format.html # index.html.erb

View file

@ -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

View file

@ -55,9 +55,19 @@
<%= render '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) %>
<%= reward.name %>
<div class='edit'>
<%= link_to 'Edit', edit_reward_path(reward) %>
</div>
</li>
<% end %>
</div>
</div>
</div>
<%= link_to 'New Reward', new_reward_path %>
</td>
</tr>
</table>

View file

@ -19,14 +19,6 @@
<%= f.label :value %><br />
<%= f.number_field :value %>
</div>
<div class="field">
<%= f.label :position %><br />
<%= f.number_field :position %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>

View file

@ -1,29 +0,0 @@
<h1>Listing rewards</h1>
<table>
<tr>
<th>Name</th>
<th>Value</th>
<th>Position</th>
<th>User</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @rewards.each do |reward| %>
<tr>
<td><%= reward.name %></td>
<td><%= reward.value %></td>
<td><%= reward.position %></td>
<td><%= reward.user_id %></td>
<td><%= link_to 'Show', reward %></td>
<td><%= link_to 'Edit', edit_reward_path(reward) %></td>
<td><%= link_to 'Destroy', reward, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Reward', new_reward_path %>

View file

@ -1,25 +0,0 @@
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @reward.name %>
</p>
<p>
<b>Value:</b>
<%= @reward.value %>
</p>
<p>
<b>Position:</b>
<%= @reward.position %>
</p>
<p>
<b>User:</b>
<%= @reward.user_id %>
</p>
<%= link_to 'Edit', edit_reward_path(@reward) %> |
<%= link_to 'Back', rewards_path %>