-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kld/master - finished wave 4 #101
base: kld/master
Are you sure you want to change the base?
Changes from all commits
89f9167
dc681f1
52296cf
a70cd26
a567978
c20df6b
867d4d2
c3eea9a
e75d9ce
8e38b04
90a2c9e
107c8c9
e31eade
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the people controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class PeopleController < ApplicationController | ||
before_filter :last_page | ||
|
||
def index | ||
@people = Person.all | ||
end | ||
|
||
def show | ||
id = params[:id] | ||
@person = Person.find(id) | ||
end | ||
|
||
def showtasks | ||
id = params[:id] | ||
@person = Person.find(id) | ||
@tasks = Person.find(id).tasks | ||
end | ||
|
||
def new | ||
@person = Person.new | ||
end | ||
|
||
def create | ||
Person.create(person_params[:person]) | ||
redirect_to "/people" | ||
end | ||
|
||
def edit | ||
id = params[:id] | ||
@person = Person.find(id) | ||
end | ||
|
||
def update | ||
id = params[:id] | ||
@person = Person.find(id) | ||
@person.update( | ||
name: person_params[:person][:name] | ||
) | ||
redirect_to "/people" | ||
end | ||
|
||
private | ||
|
||
def person_params | ||
params.permit(person:[:id, :name]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this should permit |
||
end | ||
|
||
def last_page | ||
session[:last_page] = request.env['HTTP_REFERER'] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PeopleHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Person < ActiveRecord::Base | ||
has_many :tasks | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Task < ActiveRecord::Base | ||
belongs_to :person | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p class="center_task"> | ||
<% if session[:last_page] %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code might be simpler if you used a small amount of javascript: <%= button_tag "Go Back", onclick: "History.back();" %> At that point you would not need to store any information in the |
||
<%= link_to "Go Back", session[:last_page] %> | ||
<% end %> | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= form_for @person, :html => {:class => "form-inline"} do |f| %> | ||
<fieldset> | ||
<legend><%= legend_text %></legend> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<%= f.submit value: "#{button_text}", class: "new_button"%> | ||
</fieldset> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= render partial: 'form', locals: {method_type: :patch, button_text: "Update Person", legend_text: "Edit Person"} %> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1>People</h1> | ||
<div class="center"> | ||
<% @people.each do |person| %> | ||
<span> | ||
<a href="/people/<%= person.id %>" > | ||
<%= person.name %> - <%= person.tasks.where({:completed => nil}).length %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest moving a small bit of this code into the Person model class: def tasks_uncompleted
return self.tasks.where({:completed => nil})
end Then you can use |
||
<% unless person.tasks.where({:completed => nil}).length == 1 %> | ||
uncompleted tasks | ||
<% else %> | ||
uncompleted task | ||
<% end %> | ||
</a> | ||
</span> | ||
<br /> | ||
<% end %> | ||
</div> | ||
<p class="add_new"> | ||
<a href="/people/new">Add a new person</a> | ||
</p> | ||
<p class="add_new"> | ||
<a href="/tasks/">See all tasks</a> | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= render partial: 'form', locals: {button_text: "Add New Person", legend_text: "Add New Person"} %> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1><%= @person.name %></h1> | ||
<div class="center"> | ||
<span> | ||
<a href="/people/<%= @person.id %>/tasks">See task list </a> | ||
<br /> | ||
<br /> | ||
<a href="/people/<%= @person.id %>/edit">Edit person </a> | ||
</span> | ||
</div> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<h1><%= @person.name %></h1> | ||
<div class="center"> | ||
<span> | ||
To Do: | ||
<br /> | ||
<% @tasks.each do |task| %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code within this loop through |
||
<% if task.completed.nil? %> | ||
<a href="/tasks/<%= task.id %>"><%= task.name %></a> | ||
<br /> | ||
<% end %> | ||
<% end %> | ||
</span> | ||
<br /> | ||
<br /> | ||
<br /> | ||
<span> | ||
Completed: | ||
<br /> | ||
<% @tasks.each do |task| %> | ||
<% if !task.completed.nil? %> | ||
<a href="/tasks/<%= task.id %>" class="strikethrough"><%= task.name %></a> | ||
<br /> | ||
<% end %> | ||
<% end %> | ||
</span> | ||
<br /> | ||
</div> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p class="center_task"> | ||
<% if session[:last_page] %> | ||
<%= link_to "Go Back", session[:last_page] %> | ||
<% end %> | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<%= render partial: 'form', locals: {method_type: :patch, button_text: "Update Task", legend_text: "Edit Task"} %> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<%= render partial: 'form', locals: {button_text: "Create Task", legend_text: "Add Task"} %> | ||
<%= render partial: 'backbutton' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreatePeople < ActiveRecord::Migration | ||
def change | ||
create_table :people do |t| | ||
t.string :name | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddPersonIndexToTasks < ActiveRecord::Migration | ||
def change | ||
change_table :tasks do |t| | ||
add_column :tasks, :person_id, :integer | ||
end | ||
|
||
add_index :tasks, :person_id | ||
end | ||
|
||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this we could reuse the
@person
variable as it should be the same as callingPerson.find(id)
again.