Created
September 9, 2012 01:32
-
-
Save telagraphic/3681928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Action < ActiveRecord::Base | |
belongs_to :day | |
attr_accessible :energy, :mood, :overall | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionsController < ApplicationController | |
before_filter :get_day | |
def get_day | |
@day = Day.find(params[:day_id]) | |
end | |
def create | |
@action = @day.actions.new(params[:action]) | |
if @action.save | |
redirect_to @day | |
else | |
render "day/show" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Day < ActiveRecord::Base | |
attr_accessible :sleep, :wake | |
has_one :action | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DaysController < ApplicationController | |
before_filter :get_day, :only => [:show, :edit, :update, :destroy] | |
def get_day | |
@day = Day.find(params[:id]) | |
end | |
def index | |
@days = Day.all | |
end | |
def show | |
@action = @day.action.new | |
end | |
def new | |
@day = Day.new | |
end | |
def create | |
@day = Day.new(params[:day]) | |
if @day.save | |
redirect_to days_path | |
else | |
render "new" | |
end | |
end | |
def edit | |
@day = Day.find(params[:id]) | |
end | |
def update | |
if @day.update_attributes(params[:day]) | |
redirect_to days_path | |
else | |
render "edit" | |
end | |
end | |
def destroy | |
@day.destroy | |
redirect_to days_path | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Life::Application.routes.draw do | |
resources :days do | |
resources :actions | |
end | |
root :to => "Days#index" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= link_to "Back", days_path %> | |
<table id="days-list"> | |
<thead> | |
<tr> | |
<th>Date</th> | |
<th>Wake</th> | |
<th>Sleep</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td><%= @day.created_at.strftime("%x") %></td> | |
<td><%= @day.wake %></td> | |
<td><%= @day.sleep %></td> | |
<td><%= link_to "Edit", edit_day_path(@day) %></td> | |
<td><%= link_to "Delete", @day, :confirm => "Sure?", :method => :delete %></td> | |
</tr> | |
</tbody> | |
</table> | |
<%= render "actions/new_action" %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment