質問編集履歴

3

意図的に内容を抹消する行為にあたるため

2021/05/24 02:02

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Rssssaaaaaaaaaa
1
+ Rails URL直打ちで詳細画面へ行かない様にしたい
test CHANGED
@@ -1 +1,143 @@
1
+ Railsで簡単な掲示板アプリを作成しています。
2
+
3
+ localhost:3000/projects/2/tasks/1のようにURLを入力すると、projectに紐づいていないTaskの詳細情報が確認できてしまうことが分かりました。
4
+
5
+ URL直打ちで詳細画面へ行かない様にしたいのですが、どの様にすれば良いか分からず詰まっております。
6
+
7
+ ```
8
+
9
+ class TasksController < ApplicationController
10
+
11
+ before_action :set_project
12
+
13
+ before_action :set_task, only: %i[show edit update destroy]
14
+
15
+ def index
16
+
17
+ @tasks = @project.tasks
18
+
19
+ end
20
+
21
+ def show; end
22
+
23
+ def new
24
+
25
+ @task = Task.new
26
+
27
+ end
28
+
29
+ def edit; end
30
+
31
+ def create
32
+
33
+ @task = Task.new(task_params)
34
+
35
+ if @task.save
36
+
37
+ redirect_to [@project, @task], notice: 'Task was successfully created.'
38
+
39
+ else
40
+
41
+ render :new
42
+
43
+ end
44
+
45
+ end
46
+
47
+ def update
48
+
49
+ if @task.update(task_params)
50
+
51
+ redirect_to [@project, @task], notice: 'Task was successfully updated.'
52
+
53
+ else
54
+
55
+ render :edit
56
+
57
+ end
58
+
59
+ end
60
+
61
+ def destroy
62
+
63
+ @task.destroy
64
+
65
+ redirect_to project_tasks_url, notice: 'Task was successfully destroyed.'
66
+
67
+ end
68
+
69
+ private
70
+
71
+ def set_project
72
+
73
+ @project = Project.find(params[:project_id])
74
+
75
+ end
76
+
77
+ def set_task
78
+
79
+ binding.pry
80
+
1
- thankyou ! aaaaaaaaaasdsadsadadsadasdsa
81
+ @task = Task.find(params[:id])
82
+
83
+ end
84
+
85
+ def task_params
86
+
87
+ params.require(:task).permit(:title, :status, :deadline, :completion_date, :description).merge(project_id: params[:project_id])
88
+
89
+ end
90
+
91
+ end
92
+
93
+ ```
94
+
95
+ ```show
96
+
97
+ <p id="notice"><%= notice %></p>
98
+
99
+ <p>
100
+
101
+ <strong>Title:</strong>
102
+
103
+ <%= @task.title %>
104
+
105
+ </p>
106
+
107
+ <p>
108
+
109
+ <strong>Status:</strong>
110
+
111
+ <%= @task.status %>
112
+
113
+ </p>
114
+
115
+ <p>
116
+
117
+ <strong>Deadline:</strong>
118
+
119
+ <%= @task.deadline.strftime('%Y-%m-%d %H:%M') if @task.deadline? %>
120
+
121
+ </p>
122
+
123
+ <p>
124
+
125
+ <strong>Completion date:</strong>
126
+
127
+ <%= @task.completion_date %>
128
+
129
+ </p>
130
+
131
+ <p>
132
+
133
+ <strong>Description:</strong>
134
+
135
+ <%= @task.description %>
136
+
137
+ </p>
138
+
139
+ <%= link_to 'Edit', edit_project_task_path(@task.project_id, @task) %> |
140
+
141
+ <%= link_to 'Back', project_tasks_path %>
142
+
143
+ ```

2

aaaaaasadaasdasdsadsadasdadadad

2021/05/24 02:02

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Rails URL直打ちで詳細画面へ行かない様にしたい
1
+ Rssssaaaaaaaaaa
test CHANGED
@@ -1,181 +1 @@
1
- Railsで簡単な掲示板アプリを作成しています。
2
-
3
- localhost:3000/projects/2/tasks/1のようにURLを入力すると、projectに紐づいていないTaskの詳細情報が確認できてしまうことが分かりました。
4
-
5
- URL直打ちで詳細画面へ行かない様にしたいのですが、どの様にすれば良いか分からず詰まっております。
6
-
7
- ```
8
-
9
- class TasksController < ApplicationController
10
-
11
- before_action :set_project
12
-
13
- before_action :set_task, only: %i[show edit update destroy]
14
-
15
-
16
-
17
- def index
18
-
19
- @tasks = @project.tasks
20
-
21
- end
22
-
23
-
24
-
25
- def show; end
26
-
27
-
28
-
29
- def new
30
-
31
- @task = Task.new
32
-
33
- end
34
-
35
-
36
-
37
- def edit; end
38
-
39
-
40
-
41
- def create
42
-
43
- @task = Task.new(task_params)
44
-
45
-
46
-
47
- if @task.save
48
-
49
- redirect_to [@project, @task], notice: 'Task was successfully created.'
50
-
51
- else
52
-
53
- render :new
54
-
55
- end
56
-
57
- end
58
-
59
-
60
-
61
- def update
62
-
63
- if @task.update(task_params)
64
-
65
- redirect_to [@project, @task], notice: 'Task was successfully updated.'
66
-
67
- else
68
-
69
- render :edit
70
-
71
- end
72
-
73
- end
74
-
75
-
76
-
77
- def destroy
78
-
79
- @task.destroy
80
-
81
- redirect_to project_tasks_url, notice: 'Task was successfully destroyed.'
82
-
83
- end
84
-
85
-
86
-
87
- private
88
-
89
-
90
-
91
- def set_project
92
-
93
- @project = Project.find(params[:project_id])
94
-
95
- end
96
-
97
-
98
-
99
- def set_task
100
-
101
- binding.pry
102
-
103
- @task = Task.find(params[:id])
1
+ thankyou ! aaaaaaaaaasdsadsadadsadasdsa
104
-
105
- end
106
-
107
-
108
-
109
- def task_params
110
-
111
- params.require(:task).permit(:title, :status, :deadline, :completion_date, :description).merge(project_id: params[:project_id])
112
-
113
- end
114
-
115
- end
116
-
117
- ```
118
-
119
- ```show
120
-
121
- <p id="notice"><%= notice %></p>
122
-
123
-
124
-
125
- <p>
126
-
127
- <strong>Title:</strong>
128
-
129
- <%= @task.title %>
130
-
131
- </p>
132
-
133
-
134
-
135
- <p>
136
-
137
- <strong>Status:</strong>
138
-
139
- <%= @task.status %>
140
-
141
- </p>
142
-
143
-
144
-
145
- <p>
146
-
147
- <strong>Deadline:</strong>
148
-
149
- <%= @task.deadline.strftime('%Y-%m-%d %H:%M') if @task.deadline? %>
150
-
151
- </p>
152
-
153
-
154
-
155
- <p>
156
-
157
- <strong>Completion date:</strong>
158
-
159
- <%= @task.completion_date %>
160
-
161
- </p>
162
-
163
-
164
-
165
- <p>
166
-
167
- <strong>Description:</strong>
168
-
169
- <%= @task.description %>
170
-
171
- </p>
172
-
173
-
174
-
175
- <%= link_to 'Edit', edit_project_task_path(@task.project_id, @task) %> |
176
-
177
- <%= link_to 'Back', project_tasks_path %>
178
-
179
-
180
-
181
- ```

1

追加

2021/05/21 10:06

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -115,3 +115,67 @@
115
115
  end
116
116
 
117
117
  ```
118
+
119
+ ```show
120
+
121
+ <p id="notice"><%= notice %></p>
122
+
123
+
124
+
125
+ <p>
126
+
127
+ <strong>Title:</strong>
128
+
129
+ <%= @task.title %>
130
+
131
+ </p>
132
+
133
+
134
+
135
+ <p>
136
+
137
+ <strong>Status:</strong>
138
+
139
+ <%= @task.status %>
140
+
141
+ </p>
142
+
143
+
144
+
145
+ <p>
146
+
147
+ <strong>Deadline:</strong>
148
+
149
+ <%= @task.deadline.strftime('%Y-%m-%d %H:%M') if @task.deadline? %>
150
+
151
+ </p>
152
+
153
+
154
+
155
+ <p>
156
+
157
+ <strong>Completion date:</strong>
158
+
159
+ <%= @task.completion_date %>
160
+
161
+ </p>
162
+
163
+
164
+
165
+ <p>
166
+
167
+ <strong>Description:</strong>
168
+
169
+ <%= @task.description %>
170
+
171
+ </p>
172
+
173
+
174
+
175
+ <%= link_to 'Edit', edit_project_task_path(@task.project_id, @task) %> |
176
+
177
+ <%= link_to 'Back', project_tasks_path %>
178
+
179
+
180
+
181
+ ```