-
Notifications
You must be signed in to change notification settings - Fork 47
Time - Yaz #47
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
base: master
Are you sure you want to change the base?
Time - Yaz #47
Changes from all commits
11afbe1
690df95
1de17d1
4c58c36
c7876b6
16bcc93
6a043e3
463d737
8526f45
aa03ac7
2a4e292
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,11 @@ | ||
| // Place all the styles related to the Tasks controller here. | ||
| // They will automatically be included in application.css. | ||
| // You can use Sass (SCSS) here: https://sass-lang.com/ | ||
| .task-list { | ||
| color: blueviolet; | ||
| align-content: center; | ||
| } | ||
|
|
||
| .completed { | ||
| text-decoration: line-through; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| class TasksController < ApplicationController | ||
|
|
||
| def index | ||
| @tasks = Task.all | ||
| end | ||
|
|
||
| def show | ||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| head :not_found | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def new | ||
| @task = Task.new | ||
| end | ||
|
|
||
| def create | ||
| @task = Task.new(name: params[:task][:name], description: params[:task][:description]) | ||
| if @task.save | ||
| redirect_to task_path(@task) | ||
| return | ||
| else | ||
| render :new | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def edit | ||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| head :not_found | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def update | ||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| head :not_found | ||
| return | ||
| elsif @task.update( | ||
| name: params[:task][:name], | ||
| description: params[:task][:description], | ||
| completed_at: params[:task][:completed_at] | ||
| ) | ||
| redirect_to task_path(@task) | ||
| return | ||
| else | ||
| render :edit | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| head :not_found | ||
| return | ||
| else | ||
| @task.destroy | ||
| redirect_to tasks_path | ||
| return | ||
| end | ||
| end | ||
|
|
||
| def mark_complete | ||
|
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 haven't figured out why but this is not succeeding for me in updating the task to complete. |
||
| @task = Task.find_by(id: params[:id]) | ||
| if @task.nil? | ||
| head :not_found | ||
| return | ||
| else | ||
| @task.update(completed: true, completed_at: Time.now.to_s) | ||
| redirect_to tasks_path | ||
| return | ||
| end | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module TasksHelper | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class Task < ApplicationRecord | ||
| validates :name, presence: true | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <h2>edit task</h2> | ||
| <%= form_with model: @task do |f| %> | ||
|
|
||
| <%= f.label :name %> | ||
| <%= f.text_field :name %> | ||
|
|
||
| <%= f.label :description %> | ||
| <%= f.text_field :description %> | ||
|
|
||
| <%if @task.completed%> | ||
| <%= f.label :completed_at%> | ||
| <%= f.datetime_field :completed_at%> | ||
| <%end%> | ||
|
|
||
| <%= f.submit "update task" %> | ||
|
Comment on lines
+2
to
+15
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 is a good place to use a form partial. |
||
| <%end%> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <h2>current tasks</h2> | ||
| <main> | ||
| <ul class="task-list"> | ||
| <% @tasks.each do |task| %> | ||
| <li> | ||
| <%if task.completed %> | ||
| <%= link_to task.name, task_path(task), class: "completed"%> | ||
| <%else%> | ||
| <%= link_to task.name, task_path(task) %> | ||
| <%= link_to "(mark complete)", mark_complete_path(task), method: :patch%> | ||
| <%end%> | ||
| </li> | ||
| <%end%> | ||
| </ul> | ||
| <%= link_to "add new task", new_task_path, class: "button" %> | ||
| </main> | ||
|
|
||
| <%#= button_to "Edit #{book.title}", edit_book_path(book.id) %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <h2>add new task</h2> | ||
| <%= form_with model: @task do |f|%> | ||
| <%= f.label :name %> | ||
| <%= f.text_field :name %> | ||
|
|
||
| <%= f.label :decription %> | ||
| <%= f.text_field :description %> | ||
|
|
||
| <%= f.submit "save task" %> | ||
| <%end%> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <h2><%=@task.name%></h2> | ||
| <main> | ||
| <p><%= @task.description%></p> | ||
| <%if @task.completed%> | ||
| <p>completed at: <%= @task.completed_at %> </p> | ||
| <%end%> | ||
| <%= link_to "edit", edit_task_path(@task)%> | ||
| <span>/</span> | ||
| <%= link_to "delete", delete_task_path(@task), method: :delete%> | ||
| <br> | ||
| <br> | ||
| <%= link_to "back to all tasks", tasks_path %> | ||
| </main> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,14 @@ | ||
| Rails.application.routes.draw do | ||
| # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html | ||
| # collection of tasks | ||
|
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. In the future, it'll be important to have a root path to make your application more user-friendly. |
||
| get '/tasks', to: 'tasks#index', as: 'tasks' | ||
| get '/tasks/new', to: 'tasks#new', as: 'new_task' | ||
| post '/tasks', to: 'tasks#create' | ||
|
|
||
| # individual tasks | ||
| get '/tasks/:id', to: 'tasks#show', as: 'task' | ||
| get '/tasks/:id/edit', to: 'tasks#edit', as: 'edit_task' | ||
| patch '/tasks/:id', to: 'tasks#update' | ||
| patch '/tasks.:id', to: 'tasks#mark_complete', as: 'mark_complete' | ||
|
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 totally still works because the code uses the alias but I think you intended for this to be a |
||
| delete '/tasks/:id', to: 'tasks#destroy', as: 'delete_task' | ||
| end | ||
| 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.text :description | ||
| t.string :completed_at | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddCreatedBooleanToTasks < ActiveRecord::Migration[6.0] | ||
| def change | ||
| add_column :tasks, :completed, :boolean, default: false | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # 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_16_232451) 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.text "description" | ||
| t.string "completed_at" | ||
| t.datetime "created_at", precision: 6, null: false | ||
| t.datetime "updated_at", precision: 6, null: false | ||
| t.boolean "completed", default: false | ||
| end | ||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| require "test_helper" | ||
|
|
||
| describe Task do | ||
| # it "does a thing" do | ||
| # value(1+1).must_equal 2 | ||
| # end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.
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.
Devin marked the project as not handling non-existent tasks because the thing most people did here was a redirect but this is fine for now as well.
For MediaRanker, we will want to do a redirect in addition to flash messages to keep the user on a functioning page while also giving clear messaging to the user that what they were looking for is not there.