質問編集履歴

4

コード追加

2022/06/26 02:16

投稿

sosososo
sosososo

スコア7

test CHANGED
File without changes
test CHANGED
@@ -100,6 +100,31 @@
100
100
  <span class="user-element">アカウント名: <%= current_user.name %></span>
101
101
  </div>
102
102
  </div>
103
+
104
+ <div class="posts-contents">
105
+ <% @posts.each do |post| %>
106
+ <div class="post-area">
107
+ <figure>
108
+ <%= link_to image_tag(avatar_url(post.user), class: "posted-user-icon", alt: "ユーザーアイコン"), users_show_path(post.user_id) %>
109
+ </figure>
110
+ <%= link_to post_path(post.id) do %>
111
+ <div class="post-area-text">
112
+ <div class="posted-user-name"><%= post.user.name %>(<%= post.user.introduction %>)</div>
113
+ <div class="posted-date"><%= post.created_at %></div>
114
+ <div class="post-text">
115
+ <%= post.title %>
116
+ <%= post.post_content %>
117
+ <% unless post.avatar.blank? %>
118
+ <div class="post-pict">
119
+ <%= image_tag(post_image_url(post), class: "post-image", alt: "投稿画像") %>
120
+ </div>
121
+ <% end %>
122
+ </div>
123
+ </div>
124
+ <% end %>
125
+ </div>
126
+ <% end %>
127
+ </div>
103
128
  ```
104
129
 
105
130
  初学者でして、皆様のお知恵をお借りしたく思います。

3

ファイル名追加

2022/06/25 18:15

投稿

sosososo
sosososo

スコア7

test CHANGED
File without changes
test CHANGED
@@ -72,6 +72,8 @@
72
72
  ```
73
73
 
74
74
  ```ここに言語を入力
75
+ users_controller
76
+
75
77
  class UsersController < ApplicationController
76
78
  before_action :authenticate_user!
77
79
 
@@ -82,6 +84,8 @@
82
84
  ```
83
85
 
84
86
  ```ここに言語を入力
87
+ users/show
88
+
85
89
  <div class="box">
86
90
  <div class="field">
87
91
  <div class="user-icon-field">

2

不要コード削除

2022/06/25 18:13

投稿

sosososo
sosososo

スコア7

test CHANGED
File without changes
test CHANGED
@@ -18,23 +18,6 @@
18
18
 
19
19
  def show
20
20
  @post = Post.find(params[:id])
21
- end
22
-
23
- def create
24
- @post = current_user.posts.new(post_params)
25
- if @post.save
26
- flash[:notice] = "新規投稿しました。"
27
- else
28
- flash[:alert] = "投稿に失敗しました"
29
- end
30
- redirect_to posts_path
31
- end
32
-
33
- def destroy
34
- post = current_user.posts.find(params[:id])
35
- post.destroy
36
- flash[:notice] = "投稿を削除しました"
37
- redirect_to posts_path
38
21
  end
39
22
  ```
40
23
 
@@ -68,25 +51,6 @@
68
51
  <div class="field">
69
52
  <span class="user-element">タイトル: <%= @post.title %></span>
70
53
  </div>
71
- <div class="field">
72
- <span class="user-element">内容: <%= @post.post_content %></span>
73
- </div>
74
- <% unless @post.avatar.blank? %>
75
- <div class="field">
76
- <span class="user-element"><%= image_tag post_image_url(@post), class: "post-show-image" %></span>
77
- </div>
78
- <% end %>
79
- <div class="field">
80
- <span class="user-element">投稿日時: <%= @post.created_at.strftime('%Y/%m/%d %H:%M') %></span>
81
- </div>
82
- <div class="field">
83
- <span class="user-element"><%= link_to "戻る", :back, class: "" %></span>
84
- </div>
85
- <% if @post.user_id == current_user.id %>
86
- <div class="field">
87
- <span class="user-element"><%= link_to "削除", @post, method: :delete, data: {confirm: "本当に削除しますか?"} %></span>
88
- </div>
89
- <% end %>
90
54
  ```
91
55
 
92
56
  ```ここに言語を入力
@@ -100,12 +64,6 @@
100
64
  <div class="posted-date"><%= post.created_at.strftime('%Y/%m/%d %H:%M') %></div>
101
65
  <div class="post-text">
102
66
  <%= post.title %>
103
- <%= post.post_content %>
104
- <% unless post.avatar.blank? %>
105
- <div class="post-pict">
106
- <%= image_tag(post_image_url(post), class: "post-image", alt: "投稿画像") %>
107
- </div>
108
- <% end %>
109
67
  </div>
110
68
  </div>
111
69
  <% end %>
@@ -122,6 +80,7 @@
122
80
  end
123
81
  end
124
82
  ```
83
+
125
84
  ```ここに言語を入力
126
85
  <div class="box">
127
86
  <div class="field">

1

コード追加

2022/06/25 18:08

投稿

sosososo
sosososo

スコア7

test CHANGED
File without changes
test CHANGED
@@ -111,8 +111,34 @@
111
111
  <% end %>
112
112
  </div>
113
113
  <% end %>
114
+ ```
114
115
 
116
+ ```ここに言語を入力
117
+ class UsersController < ApplicationController
118
+ before_action :authenticate_user!
119
+
120
+ def show
121
+ @posts = current_user.posts.all
122
+ end
123
+ end
115
124
  ```
125
+ ```ここに言語を入力
126
+ <div class="box">
127
+ <div class="field">
128
+ <div class="user-icon-field">
129
+ <% if current_user.image? %>
130
+ <%= image_tag current_user.image.url %>
131
+ <% else %>
132
+ <%= image_tag avatar_url(current_user), class: "user-image", alt: "ユーザーアイコン" %>
133
+ <% end %>
134
+ </div>
135
+ </div>
136
+ <div class="field">
137
+ <span class="user-element">アカウント名: <%= current_user.name %></span>
138
+ </div>
139
+ </div>
140
+ ```
141
+
116
142
  初学者でして、皆様のお知恵をお借りしたく思います。
117
143
  宜しくお願い申し上げます。
118
144