teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

変更

2019/07/30 10:29

投稿

k_yusuke
k_yusuke

スコア19

title CHANGED
File without changes
body CHANGED
@@ -145,7 +145,6 @@
145
145
 
146
146
  def show
147
147
  @tour=Tour.find_by(id: params[:id])
148
- @like=Like.new
149
148
  @comments = Comment.where(tour_id: @tour.id)
150
149
  @comment = Comment.new
151
150
  end
@@ -194,6 +193,7 @@
194
193
  .form-inputs.form_group
195
194
  = f.input :content,
196
195
  input_html: { autocomplete: "content",class:"form-control" }
196
+ =hidden_field_tag :tour_id,@tour.id
197
197
  = f.button :submit, "Comment!",
198
198
  input_html: { class:" btn btn-primary " }
199
199
  ```

1

変更

2019/07/30 10:28

投稿

k_yusuke
k_yusuke

スコア19

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
3
  rails tutorialの応用で記事(tourモデル)に対してコメントする機能を実装中です。
4
- `app/wiews/tours/show/index.html.haml`にコメントを反映させたいと考えています。
4
+ `app/wiews/tours/show.html.haml`にコメントを反映させたいと考えています。
5
5
  ↓の記事を参考にしました
6
6
  [Railsでコメント機能をつくってみよう](https://qiita.com/nojinoji/items/2034764897c6e91ef982)
7
7
  ### 問題点
@@ -153,7 +153,7 @@
153
153
  end
154
154
 
155
155
  ```
156
- app/wiews/tours/show/index.html.haml
156
+ app/wiews/tours/show.html.haml
157
157
  ```ruby
158
158
  %h1.page_title ツアー詳細
159
159
  .card
@@ -197,6 +197,27 @@
197
197
  = f.button :submit, "Comment!",
198
198
  input_html: { class:" btn btn-primary " }
199
199
  ```
200
+ app/wiews/tours/index.html.haml
201
+ ```ruby
202
+ %h1.page_title tour一覧
203
+ =render "shared/search"
204
+ = page_entries_info @tours
205
+ = paginate @tours
206
+ -@tours.each do |tour|
207
+ .card
208
+ .card-body
209
+ %h4.card-title
210
+ %smallタイトル:
211
+ #{tour.tourname}
212
+ %h6.card-subtitle.mb-2.text-muted
213
+ %small製作者:
214
+ #{tour.user.username}
215
+ %p.card-text
216
+ = tour.tourcontent
217
+ = link_to "詳細",tour_path(tour.id),class:"card-link"
218
+ = paginate @tours
219
+
220
+ ```
200
221
  app/config/routes.rb
201
222
  ```ruby
202
223
  Rails.application.routes.draw do