Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Adapt routes and views #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adapt routes and views #21

wants to merge 1 commit into from

Conversation

Polo2
Copy link
Contributor

@Polo2 Polo2 commented Sep 27, 2018

Basic set up to navigate between dependencies and comments

@Polo2 Polo2 requested review from a user, michaelbaudino and thibaultdalban September 27, 2018 15:43
@michaelbaudino michaelbaudino temporarily deployed to toolbox-staging-pr-21 September 27, 2018 15:43 Inactive
@@ -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 }
Copy link
Member

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 🤔

Copy link

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…)

@@ -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 ] } %>
Copy link
Member

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.

Copy link

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 !"
Copy link
Member

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 }
Copy link

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…)

@@ -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 ] } %>
Copy link

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>
Copy link

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 %>
Copy link

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.

@Polo2 Polo2 force-pushed the adapt-routes-and-views branch from 9db287f to d56f90b Compare September 28, 2018 12:36
@Polo2 Polo2 temporarily deployed to toolbox-staging-pr-21 September 28, 2018 12:36 Inactive
@Polo2 Polo2 force-pushed the adapt-routes-and-views branch from d56f90b to c0d7f95 Compare September 28, 2018 12:38
@Polo2 Polo2 temporarily deployed to toolbox-staging-pr-21 September 28, 2018 12:38 Inactive
@Polo2 Polo2 requested review from michaelbaudino and a user September 28, 2018 12:39
@@ -14,6 +14,7 @@
<% @dependencies.each do |dependency| %>
<tr>
<td><%= dependency.name %></td>
<td><%= dependency.comments.count %> comments</td>
Copy link
Member

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

@@ -23,7 +23,8 @@

<div class="field">
<%= form.label :dependency_id %>
<%= form.text_field :dependency_id %>
<%= select_tag(:dependency_id,
Copy link
Member

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.

@Polo2 Polo2 force-pushed the adapt-routes-and-views branch from 3f30003 to c3721ad Compare October 4, 2018 13:34
@Polo2 Polo2 had a problem deploying to toolbox-staging-pr-21 October 4, 2018 13:34 Failure
@Polo2 Polo2 requested a review from thibaultdalban October 4, 2018 13:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants