質問編集履歴
1
必要情報の記載が足りないとのご指摘を受けたので、上から順にcontroller・routes・viewを追加致しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,6 +27,59 @@
|
|
27
27
|
<% end %>
|
28
28
|
</div>
|
29
29
|
|
30
|
+
|
31
|
+
class PostsController < ApplicationController
|
32
|
+
def index
|
33
|
+
@posts = Post.all.order(created_at: :desc)
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
@post = Post.find_by(id: params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
def new
|
41
|
+
end
|
42
|
+
|
43
|
+
def create
|
44
|
+
@post = Post.new(content: params[:content])
|
45
|
+
@post.save
|
46
|
+
redirect_to("/posts/index")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Rails.application.routes.draw do
|
51
|
+
|
52
|
+
get "posts/index" => "posts#index"
|
53
|
+
get "posts/new" => "posts#new"
|
54
|
+
get "posts/:id" => "posts#show"
|
55
|
+
post "posts/create" => "posts#create"
|
56
|
+
|
57
|
+
get "/" => "home#top"
|
58
|
+
get "about" => "home#about"
|
59
|
+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
60
|
+
end
|
61
|
+
|
62
|
+
<header>
|
63
|
+
<div class="header-logo">
|
64
|
+
<a href="/">TweetApp</a>
|
65
|
+
</div>
|
66
|
+
<ul class="header-menus">
|
67
|
+
<li>
|
68
|
+
<a href="/about">TweetAppとは</a>
|
69
|
+
</li>
|
70
|
+
</ul>
|
71
|
+
</header>
|
72
|
+
|
73
|
+
|
74
|
+
<div class="main posts-index">
|
75
|
+
<div class="container">
|
76
|
+
<% @posts.each do |post| %>
|
77
|
+
<div class="posts-index-item">
|
78
|
+
<%= link_to(post.content, "/posts/#{post.id}") %>
|
79
|
+
</div>
|
80
|
+
<% end %>
|
81
|
+
</div>
|
82
|
+
</div>
|
30
83
|
```
|
31
84
|
|
32
85
|
|