質問編集履歴
1
追記、質問の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
**Routing Error**
|
5
5
|
**No route matches [GET] "/users/sign_out"**
|
6
6
|
というエラーが発生しました。原因ご存じないでしょうか?
|
7
|
-
|
7
|
+
教材(再掲) https://maki-nomad.com/rails-beginner-2/
|
8
8
|
|
9
9
|
**_header.html.erb (エラー発生箇所)** ↓
|
10
10
|
```
|
@@ -50,13 +50,93 @@
|
|
50
50
|
DELETE になっていたので、ルーティングを書き換えれば
|
51
51
|
直るのではないかと考えたのですが、参考にした記事(https://qiita.com/life_code/items/b148643312f13096ac7a)
|
52
52
|
と自分のroutes.rb の書き方がかなり異なっていたため、
|
53
|
-
|
54
53
|
routes.rb(参考記事)↓
|
55
54
|
```
|
56
55
|
resources :tweets, only: [:index, :show, :new, :create, :destroy, :edit, :update] do
|
57
56
|
```
|
58
57
|
今回の場合どのように書けばよいのかわかりませんでした。
|
59
58
|
もし何かご存知であれば教えていただけないでしょうか?
|
59
|
+
**追記(2022.6.21)**
|
60
|
+
> こちらはRails 6を前提としています。Rails 7ではフロントエンドに改変が
|
61
|
+
>入っていますので、そのままでは正しく動きません。
|
62
|
+
との回答を頂いたので rails 7 の rails 6 からの変更点を調べました。
|
63
|
+
https://qiita.com/ryohashimoto/items/f5382478c78f296d8291
|
64
|
+
↑こちらの記事には
|
65
|
+
> 以前のバージョンでは、button_toタグはHTTPメソッドとして、POSTを使用する
|
66
|
+
> ようになっていましたが、Rails 7からはPATCHを使用するようになりました。
|
67
|
+
と書かれていたので ~~_to タグを書き直すのではないかと考えたのですが、
|
68
|
+
どのように書き直せば良いかわかりませんでした。
|
69
|
+
フロントエンド部分をどう書き直すべきでしょうか?
|
70
|
+
**_header.html.erb (エラー発生箇所、再掲)** ↓
|
71
|
+
```
|
72
|
+
<header>
|
73
|
+
<div class="header-logo">
|
74
|
+
Rails beginner
|
75
|
+
</div>
|
76
|
+
<ul>
|
77
|
+
<li>
|
78
|
+
<%= link_to("ログアウト", "/users/sign_out", method: :delete, data: {confirm: "本当にログアウトしますか?"}) %>
|
79
|
+
</li>
|
80
|
+
</ul>
|
81
|
+
</header>
|
82
|
+
```
|
83
|
+
application.html.erb ↓
|
84
|
+
```
|
85
|
+
<!DOCTYPE html>
|
86
|
+
<html>
|
87
|
+
<head>
|
88
|
+
<title>Sample14</title>
|
89
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
90
|
+
<%= csrf_meta_tags %>
|
91
|
+
<%= csp_meta_tag %>
|
92
|
+
|
93
|
+
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
94
|
+
<%= javascript_importmap_tags %>
|
95
|
+
</head>
|
96
|
+
|
97
|
+
<body>
|
98
|
+
<%= render 'layouts/header' %>
|
99
|
+
<p><%= notice %></p>
|
100
|
+
<p><%= alert %></p>
|
101
|
+
<div class="container"><%= yield %></div>
|
102
|
+
</body>
|
103
|
+
</html>
|
104
|
+
|
105
|
+
```
|
106
|
+
qusetions_controller.rb
|
107
|
+
```
|
108
|
+
class QuestionsController < ApplicationController
|
109
|
+
def index
|
110
|
+
@test = "テストテキスト" #@はインスタンス変数 これは文字列を出力する
|
111
|
+
end
|
112
|
+
|
113
|
+
def show
|
114
|
+
@question = Question.find(params[:id])
|
115
|
+
end
|
116
|
+
def new
|
117
|
+
@question = Question.new #空のインスタンスを作り@questionに代入してる
|
118
|
+
end
|
119
|
+
|
120
|
+
def create
|
121
|
+
@question = Question.new(question_params)
|
122
|
+
if @question.save
|
123
|
+
flash[:notice] = "成功!"
|
124
|
+
redirect_to("/questions/#{@question.id}")
|
125
|
+
else
|
126
|
+
flash.now[:alert] = "失敗!"
|
127
|
+
render("questions/new")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
private
|
131
|
+
def question_params
|
132
|
+
params.require(:question).permit(:title, :body)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
```
|
136
|
+
index.html.erb
|
137
|
+
```
|
138
|
+
<%= @test %>
|
139
|
+
```
|
60
140
|

|
61
141
|

|
62
142
|
|