-
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
Final wave (4) #106
base: rmt/master
Are you sure you want to change the base?
Final wave (4) #106
Changes from all commits
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 |
---|---|---|
|
@@ -85,3 +85,8 @@ opacity: 0.6; | |
.button_to { | ||
display: inline; | ||
} | ||
|
||
.button-wrapper { | ||
color: red; | ||
font-size: 1.2em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class PeopleController < ApplicationController | ||
def index | ||
@people = Person.all | ||
end | ||
|
||
def show | ||
id = params[:id] | ||
@person = Person.find(id) | ||
@tasks = @person.tasks | ||
end | ||
|
||
def task_by_person | ||
id = params[:id] | ||
@person_tasks = Person.find(id).tasks | ||
@person = Person.find(id) | ||
|
||
end | ||
|
||
# def task_by_person | ||
# | ||
# 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,11 @@ | ||
class Person < ActiveRecord::Base | ||
has_many :tasks | ||
|
||
def self.incomplete(pers_id) | ||
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 like the idea to use a class method here to extend the vocabulary associated with the As we'll seen soon enough, you can actually move this method into the This will allow you to view all incomplete tasks with |
||
person = Person.find(pers_id) | ||
tasks = person.tasks | ||
incomplete = tasks.where(completed_date: nil) | ||
return incomplete.length | ||
end | ||
|
||
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,9 @@ | ||
<h1> These people do tasks: </h1> | ||
|
||
<ul> | ||
<% @people.each do |person| %> | ||
<li> | ||
<%= link_to "#{person.name}", "/people/#{person.id}" %>, aka <%= person.alt_name %> | ||
</li> | ||
<% end %> | ||
</ul> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1> All of <%= @person.name %>'s Uncompleted Tasks:</h1> | ||
|
||
<ul> | ||
<% @tasks.each do |task| %> | ||
<% if task.completed_date == nil %> | ||
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. We have a check like this throughout the codebase, and we could "Metzatize" it (very, very slightly) by moving it into the Task model class: class Task < ActiveRecord::Base
def completed?
return completed_date == nil
end
end That way our view logic doesn't have to "know" that a task is considered incomplete specifically because that field is nil. In this case its a very subtle difference, I think it's good practice for separating the concerns between Model and View in the MVC pattern. We'll start having more complex model logic soon and the distinction will probably become more clear over time. |
||
<li> | ||
<p><%= @person.alt_name %>'s chore: <%= task.name %></p> | ||
</li> | ||
<% end %> | ||
<% end %> | ||
<p>You have <%= Person.incomplete(@person.id) %> chores left to do</p> | ||
</ul> | ||
|
||
<%= link_to "Back to my page", "/people/#{@person.id}/tasks" %> | ||
|
||
<%= link_to "Back to my peeps", "/people" %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h1> All of <%= @person.name %>'s Tasks:</h1> | ||
|
||
<ul> | ||
<% @person_tasks.each do |task| %> | ||
<% if task.completed_date != nil %> | ||
<li> | ||
<p class="strike"><%= task.name %></p> | ||
</li> | ||
<% else %> | ||
<li> | ||
<p><%= task.name %></p> | ||
</li> | ||
<% end %> | ||
<% end %> | ||
</ul> | ||
|
||
<%= link_to "Take me back", "/tasks" %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreatePeople < ActiveRecord::Migration | ||
def change | ||
create_table :people do |t| | ||
t.string :name | ||
t.string :alt_name | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ModifyTasks < ActiveRecord::Migration | ||
def change | ||
change_table :tasks do |t| | ||
add_column :tasks, :writer_id, :integer | ||
end | ||
|
||
add_index :tasks, :writer_id | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DeleteColumn < ActiveRecord::Migration | ||
def change | ||
remove_column :tasks, :completed | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class FixColumnName < ActiveRecord::Migration | ||
def change | ||
rename_column :tasks, :writer_id, :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.
It would be best not to commit commented-out code like this.
If we've written some code when working on a given change and decide not to use that code, it should be fine to delete it before committing.
If we want to keep hold of it in case it'll be helpful later, we can commit it to a different branch.
If we have already committed the code and later decide not to use it, we should delete it entirely (if we need it back later Git will still have the old version).