質問編集履歴

3

修正依頼に従って質問を付け加えました。

2018/03/04 10:43

投稿

momoka_sumikko
momoka_sumikko

スコア7

test CHANGED
File without changes
test CHANGED
@@ -94,9 +94,25 @@
94
94
 
95
95
  ```
96
96
 
97
+ routes.rbの中身
98
+
99
+ ```ruby
100
+
101
+ Rails.application.routes.draw do
102
+
103
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
97
104
 
98
105
 
99
106
 
107
+ resources :posts
108
+
109
+
110
+
111
+ root 'posts#index'
112
+
113
+ end
114
+
115
+ ```
100
116
 
101
117
 
102
118
 
@@ -142,9 +158,7 @@
142
158
 
143
159
  http://[自分のIPアドレス]:3000/posts/3
144
160
 
145
- config/routes.rbのファイルパ
161
+ ②routes.rbの内容をソーコードのところに載せました
146
-
147
- Users/ユーザー名/Programming/Rails/myblog/config/routes.rb
148
162
 
149
163
  ③show.html.erb のファイルパス
150
164
 

2

追記依頼にあった内容を付け加えました。

2018/03/04 10:43

投稿

momoka_sumikko
momoka_sumikko

スコア7

test CHANGED
File without changes
test CHANGED
@@ -133,3 +133,19 @@
133
133
  初心者なので、質問に足りない情報があると思います。
134
134
 
135
135
  あればそれも教えてください。
136
+
137
+
138
+
139
+ ###追記
140
+
141
+ ①アクセスしたURL(最後の数字は記事のIDによって変わります)
142
+
143
+ http://[自分のIPアドレス]:3000/posts/3
144
+
145
+ ②config/routes.rbのファイルパス
146
+
147
+ Users/ユーザー名/Programming/Rails/myblog/config/routes.rb
148
+
149
+ ③show.html.erb のファイルパス
150
+
151
+ /Users/ユーザー名/Programming/Rails/myblog/app/views/posts/show.html.erb

1

エラーが出たshow.html.erb以外の、関係ありそうなソースコードやデータベースを追加しました

2018/03/04 10:14

投稿

momoka_sumikko
momoka_sumikko

スコア7

test CHANGED
File without changes
test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  ### 該当のソースコード
40
40
 
41
-
41
+ show.html.erbのソースコード
42
42
 
43
43
  ```ruby
44
44
 
@@ -47,6 +47,56 @@
47
47
  <p><%= @post.body %></p>
48
48
 
49
49
  ```
50
+
51
+ post_controller.rbのソースコード
52
+
53
+ ```Ruby
54
+
55
+ class PostsController < ApplicationController
56
+
57
+ def index
58
+
59
+ @posts = Post.all.order(created_at: 'desc')
60
+
61
+ end
62
+
63
+
64
+
65
+ def show
66
+
67
+ @post = Post.find(params[:id])
68
+
69
+ end
70
+
71
+ end
72
+
73
+ ```
74
+
75
+ データベース内のテーブルpostsの中身
76
+
77
+ ```
78
+
79
+ sqlite> select * from posts;
80
+
81
+ id title body crea upda
82
+
83
+ ---- ------------- ---- ---- ----
84
+
85
+ 1 title 0 body 0 2018-03-04 07:37:47.681182 2018-03-04 07:37:47.681182
86
+
87
+ 2 title 1 body 1 2018-03-04 07:37:47.686789 2018-03-04 07:37:47.686789
88
+
89
+ 3 title 2 body 2 2018-03-04 07:37:47.691107 2018-03-04 07:37:47.691107
90
+
91
+ 4 title 3 body 3 2018-03-04 07:37:47.695788 2018-03-04 07:37:47.695788
92
+
93
+ 5 title 4 body 4 2018-03-04 07:37:47.700430 2018-03-04 07:37:47.700430
94
+
95
+ ```
96
+
97
+
98
+
99
+
50
100
 
51
101
 
52
102