-
Notifications
You must be signed in to change notification settings - Fork 0
Adapt routes and views #21
base: master
Are you sure you want to change the base?
Conversation
@@ -6,7 +6,7 @@ class CommentsController < ApplicationController | |||
# GET /comments | |||
# GET /comments.json | |||
def index | |||
@comments = Comment.all | |||
@comments = Comment.all.sort_by { |c| c.dependency.name } |
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.
We should actually sort this by created_at
, imho 🤔
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.
And whatever we decide for the sorting criteria, it belongs to the model, not
the controller.
Also, wouldn't #sort_by
do the sort in Ruby? If so, we should let PostgreSQL
do the work for us IMO (Comment.order name: :asc
, Comment.order created_at: :asc
…)
app/views/comments/_form.html.erb
Outdated
@@ -23,7 +23,7 @@ | |||
|
|||
<div class="field"> | |||
<%= form.label :dependency_id %> | |||
<%= form.text_field :dependency_id %> | |||
<%= form.select :dependency_id, Dependency.all.collect {|d| [ d.name, d.id ] } %> |
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.
I believe there's a Rails helper for that.
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.
- Line is too long;
- I'd favor
#map
over#collect
(but as said there might be an helper to
remove/simplify this part); - Does our coding style allow this syntax for the block? Shouldn't this be:
{ |d| [d.name, d.id] }
db/seeds.rb
Outdated
puts "#{Dependency.count} created" | ||
puts "#{Comment.count} created" | ||
|
||
puts "Happy Growing !" |
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.
This file shouldn't be here.
@@ -6,7 +6,7 @@ class CommentsController < ApplicationController | |||
# GET /comments | |||
# GET /comments.json | |||
def index | |||
@comments = Comment.all | |||
@comments = Comment.all.sort_by { |c| c.dependency.name } |
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.
And whatever we decide for the sorting criteria, it belongs to the model, not
the controller.
Also, wouldn't #sort_by
do the sort in Ruby? If so, we should let PostgreSQL
do the work for us IMO (Comment.order name: :asc
, Comment.order created_at: :asc
…)
app/views/comments/_form.html.erb
Outdated
@@ -23,7 +23,7 @@ | |||
|
|||
<div class="field"> | |||
<%= form.label :dependency_id %> | |||
<%= form.text_field :dependency_id %> | |||
<%= form.select :dependency_id, Dependency.all.collect {|d| [ d.name, d.id ] } %> |
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.
- Line is too long;
- I'd favor
#map
over#collect
(but as said there might be an helper to
remove/simplify this part); - Does our coding style allow this syntax for the block? Shouldn't this be:
{ |d| [d.name, d.id] }
@@ -14,6 +14,7 @@ | |||
<% @dependencies.each do |dependency| %> | |||
<tr> | |||
<td><%= dependency.name %></td> | |||
<td><%= "#{dependency.comments.count} comments" %></td> |
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.
<%= "#{dependency.comments.count} comments" %>
should be:
<%= dependency.comments.count %> comments
@@ -25,3 +26,4 @@ | |||
<br> | |||
|
|||
<%= link_to 'New Dependency', new_dependency_path %> | |||
<%= link_to "See Comments", comments_path %> |
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.
A final \n
is missing at end of file.
9db287f
to
d56f90b
Compare
d56f90b
to
c0d7f95
Compare
@@ -14,6 +14,7 @@ | |||
<% @dependencies.each do |dependency| %> | |||
<tr> | |||
<td><%= dependency.name %></td> | |||
<td><%= dependency.comments.count %> comments</td> |
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.
Use I18n or remove this line
c0d7f95
to
3f30003
Compare
app/views/comments/_form.html.erb
Outdated
@@ -23,7 +23,8 @@ | |||
|
|||
<div class="field"> | |||
<%= form.label :dependency_id %> | |||
<%= form.text_field :dependency_id %> | |||
<%= select_tag(:dependency_id, |
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.
Please use form.select
instead of select_tag
, specially in rails 5.2 with the new form_with
method.
3f30003
to
c3721ad
Compare
Basic set up to navigate between dependencies and comments