Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
James Miller committed Nov 2, 2009
0 parents commit d01c840
Show file tree
Hide file tree
Showing 82 changed files with 8,633 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config/app_config.yml
config/database.yml
.DS_Store
log/*.log
tmp/**/*
log/*.pid
public/system/*
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Application for managing a wedding guest list
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ApplicationController < ActionController::Base

helper :all
protect_from_forgery

end
45 changes: 45 additions & 0 deletions app/controllers/families_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class FamiliesController < ApplicationController
def index
@families = Family.all
end

def show
@family = Family.find(params[:id])
end

def new
@family = Family.new
@person = @family.people.build
end

def create
@family = Family.new(params[:family])
if @family.save
flash[:notice] = "Successfully created family."
redirect_to @family
else
render :action => 'new'
end
end

def edit
@family = Family.find(params[:id])
end

def update
@family = Family.find(params[:id])
if @family.update_attributes(params[:family])
flash[:notice] = "Successfully updated family."
redirect_to @family
else
render :action => 'edit'
end
end

def destroy
@family = Family.find(params[:id])
@family.destroy
flash[:notice] = "Successfully destroyed family."
redirect_to families_url
end
end
44 changes: 44 additions & 0 deletions app/controllers/foods_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class FoodsController < ApplicationController
def index
@foods = Food.all
end

def show
@food = Food.find(params[:id])
end

def new
@food = Food.new
end

def create
@food = Food.new(params[:food])
if @food.save
flash[:notice] = "Successfully created food."
redirect_to @food
else
render :action => 'new'
end
end

def edit
@food = Food.find(params[:id])
end

def update
@food = Food.find(params[:id])
if @food.update_attributes(params[:food])
flash[:notice] = "Successfully updated food."
redirect_to @food
else
render :action => 'edit'
end
end

def destroy
@food = Food.find(params[:id])
@food.destroy
flash[:notice] = "Successfully destroyed food."
redirect_to foods_url
end
end
44 changes: 44 additions & 0 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class GroupsController < ApplicationController
def index
@groups = Group.all
end

def show
@group = Group.find(params[:id])
end

def new
@group = Group.new
end

def create
@group = Group.new(params[:group])
if @group.save
flash[:notice] = "Successfully created group."
redirect_to @group
else
render :action => 'new'
end
end

def edit
@group = Group.find(params[:id])
end

def update
@group = Group.find(params[:id])
if @group.update_attributes(params[:group])
flash[:notice] = "Successfully updated group."
redirect_to @group
else
render :action => 'edit'
end
end

def destroy
@group = Group.find(params[:id])
@group.destroy
flash[:notice] = "Successfully destroyed group."
redirect_to groups_url
end
end
7 changes: 7 additions & 0 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MainController < ApplicationController

def index
@groups = Group.all(:order => :name, :include => :families)
end

end
21 changes: 21 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ApplicationHelper

def remove_child_link(name, f)
f.hidden_field(:_delete) + link_to_function(name, "remove_fields(this)")
end

def add_child_link(name, f, method)
fields = new_child_fields(f, method)
link_to_function(name, h("insert_fields(this, \"#{method}\", \"#{escape_javascript(fields)}\")"))
end

def new_child_fields(form_builder, method, options = {})
options[:object] ||= form_builder.object.class.reflect_on_association(method).klass.new
options[:partial] ||= method.to_s.singularize
options[:form_builder_local] ||= :f
form_builder.fields_for(method, options[:object], :child_index => "new_#{method}") do |f|
render(:partial => options[:partial], :locals => { options[:form_builder_local] => f })
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/families_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FamiliesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/foods_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FoodsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/groups_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GroupsHelper
end
22 changes: 22 additions & 0 deletions app/helpers/layout_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# These helper methods can be called in your template to set variables to be used in the layout
# This module should be included in all views globally,
# to do so you may need to add this line to your ApplicationController
# helper :layout
module LayoutHelper
def title(page_title, show_title = true)
@content_for_title = page_title.to_s
@show_title = show_title
end

def show_title?
@show_title
end

def stylesheet(*args)
content_for(:head) { stylesheet_link_tag(*args) }
end

def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
end
end
2 changes: 2 additions & 0 deletions app/helpers/main_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MainHelper
end
11 changes: 11 additions & 0 deletions app/models/family.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Family < ActiveRecord::Base

belongs_to :group

has_many :people, :dependent => :destroy

validates_presence_of :name

accepts_nested_attributes_for :people, :allow_destroy => :true

end
7 changes: 7 additions & 0 deletions app/models/food.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Food < ActiveRecord::Base

has_many :people

validates_presence_of :name

end
6 changes: 6 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Group < ActiveRecord::Base

has_many :families, :dependent => :destroy
has_many :people, :through => :families

end
8 changes: 8 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Person < ActiveRecord::Base

belongs_to :family, :counter_cache => true
belongs_to :food

validates_presence_of :name

end
35 changes: 35 additions & 0 deletions app/views/families/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<% form_for @family do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name, :class => "text medium" %>
</p>
<p>
<%= f.label :address %><br />
<%= f.text_area :address, :rows => 4, :cols => 50, :class => "textarea" %>
</p>
<p>
<%= f.label :phone %><br />
<%= f.text_field :phone, :class => "text medium" %>
</p>
<p>
<%= f.label :email %><br />
<%= f.text_field :email, :class => "text medium" %>
</p>
<p>
<%= f.label :group_id, "Group" %><br />
<%= f.select :group_id, Group.all(:order => :name).map { |g| [g.name, g.id] }, {:include_blank => "Select group..."}, :class => "drop" %>
</p>
<p>
<%= f.label :list, "List" %><br />
<%= f.select :list, [ "A List", "B List"], {}, :class => "drop" %>
</p>

<h2>People in this family</h2>
<% f.fields_for :people do |pf| %>
<%= render :partial => 'person', :locals => { :f => pf } %>
<% end %>
<p><%= add_child_link "Add person", f, :people %></p>

<p><%= f.submit "Save" %></p>
<% end %>
11 changes: 11 additions & 0 deletions app/views/families/_person.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="fields">
<p>
<%= f.text_field :name, :class => "text short" %>
<%= f.select :attending, [["Yes", true], ["No", false]], {:include_blank => "Attending?"}, :class => "drop" %>
<%= f.select :food_id, Food.all(:order => :name).map { |food| [food.name, food.id] }, {:include_blank => "Select food..."}, :class => "drop" %>
<%= remove_child_link "Remove", f %>
</p>
</div>
8 changes: 8 additions & 0 deletions app/views/families/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% title "Edit Family" %>
<%= render :partial => 'form' %>

<p>
<%= link_to "Show", @family %> |
<%= link_to "View All", families_path %>
</p>
23 changes: 23 additions & 0 deletions app/views/families/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% title "Families" %>

<table>
<tr>
<th>Name</th>
<th>People Count</th>
<th>Address</th>
<th>Group</th>
</tr>
<% for family in @families %>
<tr>
<td><%=h family.name %></td>
<td><%=h family.people_count %></td>
<td><%=h family.address %></td>
<td><%=h family.group_id %></td>
<td><%= link_to "Show", family %></td>
<td><%= link_to "Edit", edit_family_path(family) %></td>
<td><%= link_to "Destroy", family, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<p><%= link_to "New Family", new_family_path %></p>
5 changes: 5 additions & 0 deletions app/views/families/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% title "New Family" %>
<%= render :partial => 'form' %>

<p><%= link_to "Back to List", families_path %></p>
24 changes: 24 additions & 0 deletions app/views/families/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% title "Family" %>

<p>
<strong>Name:</strong>
<%=h @family.name %>
</p>
<p>
<strong>People Count:</strong>
<%=h @family.people_count %>
</p>
<p>
<strong>Address:</strong>
<%=h @family.address %>
</p>
<p>
<strong>Group:</strong>
<%=h @family.group_id %>
</p>

<p>
<%= link_to "Edit", edit_family_path(@family) %> |
<%= link_to "Destroy", @family, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View All", families_path %>
</p>
8 changes: 8 additions & 0 deletions app/views/foods/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% form_for @food do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
8 changes: 8 additions & 0 deletions app/views/foods/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% title "Edit Food" %>
<%= render :partial => 'form' %>

<p>
<%= link_to "Show", @food %> |
<%= link_to "View All", foods_path %>
</p>
Loading

0 comments on commit d01c840

Please sign in to comment.