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

Adapt routes and views - #21

Open
Polo2 wants to merge 1 commit into
masterfrom
adapt-routes-and-views
Open

Adapt routes and views#21
Polo2 wants to merge 1 commit into
masterfrom
adapt-routes-and-views

Conversation

@Polo2

@Polo2 Polo2 commented Sep 27, 2018

Copy link
Copy Markdown
Contributor

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
Comment thread app/controllers/comments_controller.rb Outdated
# GET /comments.json
def index
@comments = Comment.all
@comments = Comment.all.sort_by { |c| c.dependency.name }

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

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

Comment thread app/views/comments/_form.html.erb Outdated
<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
Copy Markdown
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
Copy Markdown

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] }

Comment thread db/seeds.rb Outdated
puts "#{Dependency.count} created"
puts "#{Comment.count} created"

puts "Happy Growing !" No newline at end of file

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

Comment thread app/controllers/comments_controller.rb Outdated
# GET /comments.json
def index
@comments = Comment.all
@comments = Comment.all.sort_by { |c| c.dependency.name }

Copy link
Copy Markdown

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

Comment thread app/views/comments/_form.html.erb Outdated
<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
Copy Markdown

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] }

Comment thread app/views/dependencies/index.html.erb Outdated
<% @dependencies.each do |dependency| %>
<tr>
<td><%= dependency.name %></td>
<td><%= "#{dependency.comments.count} comments" %></td>

Copy link
Copy Markdown

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

Comment thread app/views/dependencies/index.html.erb Outdated
<br>

<%= link_to 'New Dependency', new_dependency_path %>
<%= link_to "See Comments", comments_path %> No newline at end of file

Copy link
Copy Markdown

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 a user and michaelbaudino September 28, 2018 12:39
Comment thread app/views/dependencies/index.html.erb Outdated
<% @dependencies.each do |dependency| %>
<tr>
<td><%= dependency.name %></td>
<td><%= dependency.comments.count %> comments</td>

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

Comment thread app/views/comments/_form.html.erb Outdated
<div class="field">
<%= form.label :dependency_id %>
<%= form.text_field :dependency_id %>
<%= select_tag(:dependency_id,

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