forked from AdaGold/task-list
-
Notifications
You must be signed in to change notification settings - Fork 47
Time - Hannah T #44
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
Open
stpatrickschild
wants to merge
4
commits into
Ada-C13:master
Choose a base branch
from
stpatrickschild:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Time - Hannah T #44
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Tasks = [ | ||
| # {name: "Honey", description: "go swimming", completed_at: "Sunday evening"}, | ||
| # {name: "Calder", description: "do laundry", completed_at: "Monday night"}, | ||
| # {name: "Zoe", description: "plant flowers", completed_at: "Monday morning"}, | ||
| # {name: "Claire", description: "go to pure barre", completed_at: "yesterday miday"}, | ||
| # {name: "Darin", description: "fold cloth", completed_at: "2 min ago"}, | ||
| # {name: "Kyle", description: "High Five Somebody You Don't Know", completed_at: "a min ago"}, | ||
| # ] | ||
|
|
||
| class TasksController < ApplicationController | ||
| def index | ||
| @tasks = Task.all | ||
| end | ||
|
|
||
| def show | ||
| @task = Task.find_by(id: params[:id]) | ||
|
|
||
| if @task.nil? | ||
| redirect_to root_path | ||
| # head :not_found # you can also put 404 | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def update | ||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| redirect_to root_path | ||
| return | ||
| elsif @task.update(task_params) | ||
| redirect_to task_path(@task.id) # go to the index so we can see the task in the list | ||
| return | ||
| else # save failed :( | ||
| render :edit # show the new task form view again | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def edit | ||
| @task = Task.find_by(id: params[:id]) | ||
|
|
||
| if @task.nil? | ||
| redirect_to root_path | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| @task = Task.find_by(id: params[:id]) | ||
|
|
||
| if @task.nil? | ||
| redirect_to root_path | ||
|
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. indentation here as well. |
||
| return | ||
| else | ||
| @task.destroy | ||
| redirect_to root_path | ||
| end | ||
| end | ||
|
|
||
| def mark_complete | ||
| @task = Task.find_by(id: params[:id]) | ||
|
|
||
| if @task.completed_at.nil? | ||
| @task.completed_at = Date.today | ||
| else | ||
| @task.completed_at = nil | ||
| end | ||
| @task.save | ||
| redirect_to root_path | ||
| end | ||
|
|
||
| def new | ||
| @task = Task.new | ||
|
|
||
| end | ||
|
|
||
| def create | ||
| @task = Task.new(task_params) #instantiate a new task | ||
| if @task.save # save return true if the DB insert succeeds | ||
| # redirect_to task_path # to to the index so we can see the task in the list | ||
| redirect_to task_path(@task.id) | ||
| return | ||
| else # save filled :( | ||
| render :new # show the new task form view again | ||
| return | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def task_params | ||
| return params.require(:task).permit(:name, :description, :completed_at) | ||
| end | ||
|
|
||
|
|
||
| end | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class Task < ApplicationRecord | ||
| # t9 = Task.create(name: "Marta", description: "take shower", completed_at: "this morning"), | ||
| # t10 = Task.create(name: "Liya", description: "cut nail", completed_at: "5 min ago") | ||
| end |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <%= link_to "Tasks", tasks_path %> |
Empty file.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <h2>Edit Task</h2> | ||
|
|
||
| <%= form_with model: @task, class: 'create-task' do |f| %> | ||
| <p>Please provide the following information to edit your task in our database:</p> | ||
|
|
||
| <div> | ||
| <%= f.label :name %> | ||
| <%= f.text_field :name %> | ||
| </div> | ||
| <div> | ||
| <%= f.label :description %> | ||
| <%= f.text_area :description %> | ||
| </div> | ||
|
|
||
| <%= f.submit "Edit task", class: "edit-button" %> | ||
| <% end %> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <%= link_to "Add Task", new_task_path %> | ||
|
|
||
| <h4>Your tasks</h4> | ||
| <% if @tasks.length > 0 %> | ||
| <ol> | ||
| <% @tasks.each do |task| %> | ||
| <li> | ||
| <header><strong><%= link_to(task.name, task_path(task.id) ) %></strong></header> | ||
| <%= task.description %> | ||
|
|
||
| <p><%= link_to "Delete Task", task_path(task), method: :delete, class:"btn btn-danger", data: {confirm: "Are you sure you want to delete this task?"} | ||
| %></p> | ||
|
|
||
| <% if task.completed_at.nil? %> | ||
| <%= link_to "Mark Complete", mark_completed_path(task.id), method: :patch, class:"btn btn-primary" %> | ||
| <% else %> | ||
| <p> Completed On <%= task.completed_at %></p> | ||
| <% end %> | ||
|
|
||
| </li> | ||
| <% end %> | ||
| </ol> | ||
| <% else %> | ||
| <h3>We are out of task, can you believe it?!</h3> | ||
| <% end %> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <h2>Add new Task</h2> | ||
| <%= form_with model: @task, class: 'create-task' do |f| %> | ||
| <p>Please provide the following information to save your task to a database:</p> | ||
| <div> | ||
| <%= f.label :name %> | ||
| <%= f.text_field :name %> | ||
| </div> | ||
|
|
||
| <div> | ||
| <%= f.label :description %> | ||
| <%= f.text_area :description %> | ||
| </div> | ||
|
|
||
| <%= f.submit "Save Task", class: "save-button" %> | ||
| <% end %> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <h2><%= @task.name %></h2> | ||
| <p><%= @task.description %></p> | ||
| <p><%= link_to "Edit Task", edit_task_path(@task) %></p> | ||
| <% if @task.completed_at.nil?%> | ||
| <p>Not completed</p> | ||
| <% else %> | ||
| <p> Completed on <%= @task.completed_at %></p> | ||
| <% end %> | ||
|
|
||
| <%= link_to "All Tasks", tasks_path %> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <%= link_to "Task", task_path(@task) %> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,21 @@ | ||
| Rails.application.routes.draw do | ||
| # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html | ||
| root to: "tasks#index" | ||
| get '/tasks', to:'tasks#index', as: 'tasks' | ||
| get '/tasks/new', to: 'tasks#new', as: 'new_task' | ||
| post '/tasks', to: 'tasks#create' | ||
|
|
||
|
|
||
| # routes that deal with a specific task | ||
| get 'tasks/:id', to: 'tasks#show', as: 'task' | ||
| get '/tasks/:id/edit', to: 'tasks#edit', as: 'edit_task' | ||
| patch '/tasks/:id', to: 'tasks#update' | ||
| delete '/tasks/:id', to: 'tasks#destroy' | ||
| # This is a custom route, and in this case, the mark_completed! | ||
| patch '/tasks/:id/mark_complete', to: 'tasks#mark_complete', as: 'mark_completed' | ||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateTasks < ActiveRecord::Migration[6.0] | ||
| def change | ||
| create_table :tasks do |t| | ||
| t.string :name | ||
| t.string :description | ||
| t.string :completed_at | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # This file is auto-generated from the current state of the database. Instead | ||
| # of editing this file, please use the migrations feature of Active Record to | ||
| # incrementally modify your database, and then regenerate this schema definition. | ||
| # | ||
| # This file is the source Rails uses to define your schema when running `rails | ||
| # db:schema:load`. When creating a new database, `rails db:schema:load` tends to | ||
| # be faster and is potentially less error prone than running all of your | ||
| # migrations from scratch. Old migrations may fail to apply correctly if those | ||
| # migrations use external dependencies or application code. | ||
| # | ||
| # It's strongly recommended that you check this file into your version control system. | ||
|
|
||
| ActiveRecord::Schema.define(version: 2020_05_12_050603) do | ||
|
|
||
| # These are extensions that must be enabled in order to support this database | ||
| enable_extension "plpgsql" | ||
|
|
||
| create_table "tasks", force: :cascade do |t| | ||
| t.string "name" | ||
| t.string "description" | ||
| t.string "completed_at" | ||
| t.datetime "created_at", precision: 6, null: false | ||
| t.datetime "updated_at", precision: 6, null: false | ||
| end | ||
|
|
||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Definitely not a big deal but your indentation is a little off here.