Skip to content

Commit fe49618

Browse files
author
Theresa
committed
Fix case that user can be undefined
1 parent c196519 commit fe49618

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

app/views/comments/comments_all.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<tr>
1717
<td><%= link_to comment.exercise.title, exercise_path(comment.exercise) %></td>
1818
<td><%= comment.text %></td>
19-
<% if comment.user.first_name.nil? %>
19+
<% if !comment.user %>
20+
<td> <%= 'User undefined' %> </td>
21+
<% elsif comment.user.first_name.nil?%>
2022
<td><%= link_to "User#{comment.user.id}", user_path(comment.user)%></td>
2123
<% else %>
2224
<td><%= link_to comment.user.name, user_path(comment.user) %></td>

app/views/comments/index.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
<% @comments.each do |comment| %>
2626
<tr>
2727
<td><%= comment.text %></td>
28-
<% if comment.user.first_name.nil? %>
29-
<td><%= "User#{comment.user.id}"%></td>
28+
<% if !comment.user %>
29+
<td> <%= 'User undefined' %> </td>
30+
<% elsif comment.user.first_name.nil?%>
31+
<td><%= "User#{comment.user.id}"%></td>
3032
<% else %>
31-
<td><%= comment.user.name %></td>
33+
<td><%= comment.user.name%></td>
3234
<% end %>
3335
<td><%= comment.created_at %>
3436
<td><div class="actions btn-group" role="group">

app/views/exercises/exercises_all.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<tr>
1717
<td><%= link_to exercise.title, exercise %></td>
1818
<% if !exercise.user %>
19-
<%= 'User undefined' %>
19+
<td> <%= 'User undefined' %> </td>
2020
<% elsif exercise.user.first_name.nil?%>
2121
<td><%= link_to "User#{exercise.user.id}", user_path(exercise.user)%></td>
2222
<% else %>

app/views/exercises/show.html.erb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
<dt><%= 'Visibility' %>:</dt>
1515
<dd><%= @exercise.public ? 'public' : 'private' %></dd>
1616
<dt><%= 'Created by' %>:</dt>
17-
<% if @exercise.user %>
18-
<% if @exercise.user.first_name.nil?%>
17+
<% if !@exercise.user %>
18+
<dd><%= 'User undefined' %></dd>
19+
<% elsif @exercise.user.first_name.nil?%>
1920
<dd><%= "User#{@exercise.user.id}"%></dd>
20-
<% else %>
21-
<dd><%= @exercise.user.name %></dd>
22-
<% end %>
2321
<% else %>
24-
<dd><%= 'User undefined' %></dd>
22+
<dd><%= @exercise.user.name %></dd>
2523
<% end %>
2624
<dt><%= 'Created at' %>:</dt>
2725
<dd><%= @exercise.created_at %></dd>

0 commit comments

Comments
 (0)