質問編集履歴

3

該当ソースコードの追加

2022/05/11 17:17

投稿

milktea246
milktea246

スコア23

test CHANGED
File without changes
test CHANGED
@@ -207,6 +207,17 @@
207
207
  </div>
208
208
  </section>
209
209
  ```
210
+ index.html.erb
211
+ ```ここに言語名を入力
212
+ <h1>index</h1>
213
+
214
+ <%= @informations.each do |information| %>
215
+ <%= attachment_image_tag information, :pet_image %>
216
+ <%= information.user.nickname %>
217
+ <%= information.updated_at.strftime("%Y-%m-%d %H:%M") %>
218
+ <% end %>
219
+ ```
220
+
210
221
  ### 試したこと
211
222
 
212
223
  ・index.html.erbで現在時間を表示させようとした後に起こってしまったのでindex.html.erbの時間表示に関する記述を消してみましたが全く関係ありませんでした。

2

該当ソースコードの追加

2022/05/11 16:47

投稿

milktea246
milktea246

スコア23

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,149 @@
64
64
  end
65
65
  ```
66
66
 
67
+ show.html.erb
68
+ ```ここに言語名を入力
69
+ <section class="hero is-info">
70
+ <div class="hero-body">
71
+ <div class="container">
72
+ <h1 class="title">
73
+ ペット詳細
74
+ </h1>
75
+ </div>
76
+ </div>
77
+ </section>
78
+
79
+ <section class="section">
80
+ <div class="container">
81
+ <div class="columns is-centered">
82
+ <div class="column is-5">
83
+ <article class="panel is-link">
84
+ <p class="panel-heading">
85
+ <%= @information.user.nickname %>さんのペット
86
+ </p>
87
+ <div class="panel-block">
88
+ <p class="control">
89
+ <%= @information.user.profile %>
90
+ </p>
91
+ </div>
92
+ <%= link_to user_path(@information.user), class: "panel-block" do %>
93
+ <%= @information.user.nickname %> さんのページへ
94
+ <% end %>
95
+ </article>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <section class="section">
102
+ <div class="container">
103
+ <div class="columns is-centered">
104
+ <div class="column is-7">
105
+ <div class="card">
106
+ <div class="card-image">
107
+ <figure class="image is-4by5">
108
+ <img class="is-rounded"><%= attachment_image_tag @information, :pet_image %>
109
+ </figure>
110
+ </div>
111
+ <div class="card-content">
112
+ <div class="media">
113
+ <div class="media-content">
114
+ </div>
115
+ </div>
116
+ <div class="content">
117
+ <table class = "table is-striped">
118
+ <tbody>
119
+ <tr>
120
+ <th>ペット情報</th>
121
+ </tr>
122
+ <tr>
123
+ <td><u>名前:<%= @information.name %></u></td>
124
+ </tr>
125
+ <tr>
126
+ <td><u>性別:<%= @information.sex %></u></td>
127
+ </tr>
128
+ <tr>
129
+ <td><u>種類:<%= @information.kinds %></u></td>
130
+ </tr>
131
+ <tr>
132
+ <td><u>色:<%= @information.color %></u></td>
133
+ </tr>
134
+ <tr>
135
+ <td><u>誕生日:<%= @information.birthday %></u></td>
136
+ </tr>
137
+ </body>
138
+ </table>
139
+ <br>
140
+
141
+ <br>
142
+ <% if @information.user.id == current_user.id %>
143
+ <%= link_to "編集画面へ", edit_information_path(@information), class: "button is-info" %>
144
+ <% end %>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </section>
152
+ ```
153
+
154
+ edit.html.erb
155
+ ```ここに言語名を入力
156
+ <section class="hero is-warning">
157
+ <div class="hero-body">
158
+ <div class="container">
159
+ <h1 class="title">
160
+ ペット情報編集
161
+ </h1>
162
+ </div>
163
+ </div>
164
+ </section>
165
+
166
+ <section class="section">
167
+ <div class="container">
168
+ <div class="columns is-centered">
169
+ <div class="column is-6">
170
+ <%= form_for @information, url: informations_path, method: :post, local: true do |f| %>
171
+ <%= f.label :name, "ペットの名前", class: "label" %>
172
+ <%= f.text_field :name, class: "input" %>
173
+
174
+ <%= f.label :sex, "ペットの性別", class: "label" %>
175
+ <%= f.select :sex, {'♂': 1, '♀': 2}, { include_blank: '-'}, { class: 'select-is-primary' , required: true } %>
176
+
177
+ <%= f.label :kinds, "ペットの種類", class: "label" %>
178
+ <%= f.text_field :kinds, class: "input" %>
179
+
180
+ <%= f.label :color, "ペットの色", class: "label" %>
181
+ <%= f.text_field :color, class: "input" %>
182
+
183
+ <%= f.label :birthday, "ペットの誕生日", class: "label" %>
184
+ <%= raw sprintf(
185
+ f.date_select(
186
+ :birthday,
187
+ class:"select-is-primary",
188
+ id:"birth-date",
189
+ use_month_numbers: true,
190
+ prompt:'-',
191
+ start_year: 1950,
192
+ end_year: (Time.now.year + 10),
193
+ date_separator: '%s'),
194
+ "<p> 年 </p>", "<p> 月 </p>") + "<p> 日 </p>" %>
195
+ <br>
196
+
197
+ <br>
198
+ <%= f.label :pet_image, "ペットの写真", class: "label" %>
199
+ <%= f.attachment_field :pet_image, class: "input" %>
200
+ <br>
201
+
202
+ <br>
203
+ <%= f.submit "更新", class: "button is-primary" %>
204
+ <% end %>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ </section>
209
+ ```
67
210
  ### 試したこと
68
211
 
69
212
  ・index.html.erbで現在時間を表示させようとした後に起こってしまったのでindex.html.erbの時間表示に関する記述を消してみましたが全く関係ありませんでした。

1

前提部分の編集

2022/05/11 14:52

投稿

milktea246
milktea246

スコア23

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,8 @@
4
4
  ペットの詳細画面と編集画面を作成した後、現在時間を表示させていと思い、index.html.erbにコードを記述していたのですが、詳細画面と編集画面に遷移しようとするとエラーが発生してしまいました。
5
5
  数時間前は詳細画面と編集画面に遷移できており、詳細画面と編集画面のコードは触っていないので他のところのエラーだとおもうのですが、分からず止まってしまっています。
6
6
  createアクションは正常に動いており、DBにペット情報を登録できています。
7
+
8
+ また、今回の件とは関係がないかもしれませんが編集画面にて更新ボタンを押すとcreateアクションが動いてしまって更新したはずなのにDBに新たな情報が登録されてしまうという挙動が起きていました。
7
9
 
8
10
  ### 実現したいこと
9
11