Conversation
Task ListWhat We're Looking For
|
| @@ -0,0 +1,40 @@ | |||
| Rails.application.routes.draw do | |||
| get 'tasks/index' | |||
There was a problem hiding this comment.
I don't think we need this route definition, as we already have the tasks#index route defined on line 11.
| Rails.application.routes.draw do | ||
| get 'tasks/index' | ||
|
|
||
| get '/', to: "tasks#index", as: "home" |
There was a problem hiding this comment.
We could also define this route using the root directive and then use root_path instead of home_path throughout the rest of the codebase:
root "tasks#index"| # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
|
|
||
| get '/tasks/new', to: "tasks#new", as: 'new_task' | ||
| post "tasks", to: "tasks#create", as: "create_task" |
There was a problem hiding this comment.
This route does not need its own name, because the name for the tasks#index route (tasks) would work instead.
This is because the path portion of both routes is exactly the same (/tasks, the / at the beginning is optional).
The same applies for the route names update_task and delete_task: both of them have the exact same path (/tasks/:id) as the tasks#show route, so we can just re-use it's route name, task.
| <h1 class="title">TASKLIST</h1> | ||
| <ul> | ||
| <li class="task" ><%= link_to "Add Task", new_task_path %></li> | ||
| <li class="task" ><%= link_to "All Tasks", tasks_index_path %></li> |
There was a problem hiding this comment.
If we remove the route on line 2 in config/routes.rb then this route helper would need to be tasks_path instead of tasks_index_path, which is more in keeping with Rails conventions.
| <!-- <ol> --> | ||
| <% @tasks.each_with_index do |task, i| %> | ||
| <section> | ||
| <h3><%= "#{i + 1}. " %><%= link_to task.title, task_path(task.id), { :class => (task.complete) ? "completed" : ""} %></h3> |
There was a problem hiding this comment.
Nice use of the ternary operator to minimize repetition of this link_to code!
| <section> | ||
| <h3><%= "#{i + 1}. " %><%= link_to task.title, task_path(task.id), { :class => (task.complete) ? "completed" : ""} %></h3> | ||
|
|
||
| <% if task.complete == true %> |
There was a problem hiding this comment.
The == true is redundant here because if statements are automatically checking for truthiness, and booleans such as task.complete have "truthiness" that matches their value of true/false.
| <p><%= link_to "Mark Complete", task_path(task.id, {:task => {:complete => true, :completed_date => DateTime.now}, :refresh => true}), method: :patch %></p> | ||
| <% end %> | ||
|
|
||
| <p><%= link_to "Edit", task_path(task.id) %></p> |
There was a problem hiding this comment.
In order for this link to go to the edit form for a given task, we would need to use the edit_task_path route helper method instead of the task_path helper, which would take us to the show page.
| @@ -0,0 +1 @@ | |||
| <%= render partial: "form"%> | |||
There was a problem hiding this comment.
Because the _form.html.erb partial is only used in this one location, we should just have the code from that file in this spot. Partials can be useful for helping us DRY up our view code, but only if we are actually using them in multiple places.
Additionally, "form" is probably not the ideal name for this partial as it does not contain a form but instead actually lists all of the tasks. The partial we have called "task_summary" is probably the one that should be named "form".
| @@ -0,0 +1,15 @@ | |||
| <% button_text ||= "The button" %> | |||
| <% form_class ||= "" %> | |||
There was a problem hiding this comment.
It looks like we're not actually using the button_text and form_class variables in the rest of this file. One example of how we could use those variables is:
<%= form_for @task, html: { class: form_class } do |f| %>
<!-- the various form labels and inputs here -->
<%= f.submit button_text %>
<% end %>| @@ -0,0 +1,53 @@ | |||
| <h2>Editing Task</h2> | |||
|
|
|||
| <%= render partial: "task_summary", locals: { submit_text: "Edit"}%> | |||
There was a problem hiding this comment.
We don't use a local variable called submit_text inside of the _task_summary.html.erb partial file. I think this should probably be button_text instead.
Task List
Congratulations! You're submitting your assignment!
Comprehension Questions