質問編集履歴
4
routingについても記載しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,9 @@
|
|
14
14
|
|
15
15
|
ただ表示しているのは、まだDBに保存していないAPIから取得したデータです。
|
16
16
|
|
17
|
-
そこで
|
17
|
+
そこでコントローラでへparamsで値を渡せていません。
|
18
|
+
|
19
|
+
|
18
20
|
|
19
21
|
|
20
22
|
|
@@ -44,11 +46,11 @@
|
|
44
46
|
|
45
47
|
```
|
46
48
|
|
47
|
-
このように
|
49
|
+
このようにlonk_toメソッドで、写真をクリックすると同時に、コントローラへ値を渡したいと考えています。
|
48
50
|
|
49
51
|
ビューでは、
|
50
52
|
|
51
|
-
APIで
|
53
|
+
APIで取得したデータも表示できています。
|
52
54
|
|
53
55
|
|
54
56
|
|
@@ -74,50 +76,170 @@
|
|
74
76
|
|
75
77
|
![イメージ説明](c6a16802225449afacfa7cd0d1340fce.png)
|
76
78
|
|
79
|
+
|
80
|
+
|
81
|
+
コントローラは
|
82
|
+
|
83
|
+
```Rails
|
84
|
+
|
85
|
+
def index
|
86
|
+
|
87
|
+
@books = GoogleBooks.search(params[:search],{:count => 20})
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
# GET /books/1
|
94
|
+
|
95
|
+
# GET /books/1.json
|
96
|
+
|
97
|
+
def show
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
# GET /books/new
|
106
|
+
|
107
|
+
def new
|
108
|
+
|
109
|
+
@book = Book.new(book_params)
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
# GET /books/1/edit
|
116
|
+
|
117
|
+
def edit
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# POST /books
|
124
|
+
|
125
|
+
# POST /books.json
|
126
|
+
|
127
|
+
def create
|
128
|
+
|
129
|
+
@book = Book.new(book_params)
|
130
|
+
|
131
|
+
binding.pry #pryのgemを入れてみましたが、ここはデバッグ実行でも通過しませんでした。
|
132
|
+
|
133
|
+
respond_to do |format|
|
134
|
+
|
135
|
+
if @book.save
|
136
|
+
|
137
|
+
format.html { redirect_to @book, notice: 'Book was successfully created.' }
|
138
|
+
|
139
|
+
format.json { render :show, status: :created, location: @book }
|
140
|
+
|
141
|
+
else
|
142
|
+
|
143
|
+
format.html { render :new }
|
144
|
+
|
145
|
+
format.json { render json: @book.errors, status: :unprocessable_entity }
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
77
153
|
```
|
78
154
|
|
79
|
-
|
155
|
+
|
80
|
-
|
81
|
-
```
|
82
|
-
|
83
|
-
コントローラは
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
```Rails
|
88
|
-
|
89
|
-
# GET /books/new
|
90
|
-
|
91
|
-
def new
|
92
|
-
|
93
|
-
@book = Book.new(book_params)
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
```
|
100
|
-
|
101
|
-
ストロングパラメータで
|
102
|
-
|
103
|
-
```Rails
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def book_params
|
108
|
-
|
109
|
-
params.require(:book).permit(:title, :author, :publish, :published)
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
```
|
116
156
|
|
117
157
|
のように記載しています。
|
118
158
|
|
159
|
+
ルーティングは
|
160
|
+
|
161
|
+
> Prefix Verb URI Pattern Controller#Action
|
162
|
+
|
163
|
+
> books GET /books(.:format) books#index
|
164
|
+
|
165
|
+
> POST /books(.:format) books#create
|
166
|
+
|
167
|
+
> new_book GET /books/new(.:format) books#new
|
168
|
+
|
169
|
+
> edit_book GET /books/:id/edit(.:format) books#edit
|
170
|
+
|
171
|
+
> book GET /books/:id(.:format) books#show
|
172
|
+
|
173
|
+
> PATCH /books/:id(.:format) books#update
|
174
|
+
|
175
|
+
> PUT /books/:id(.:format) books#update
|
176
|
+
|
177
|
+
> DELETE /books/:id(.:format) books#destroy
|
178
|
+
|
179
|
+
> posts GET /posts(.:format) posts#index
|
180
|
+
|
181
|
+
> POST /posts(.:format) posts#create
|
182
|
+
|
183
|
+
> new_post GET /posts/new(.:format) posts#new
|
184
|
+
|
185
|
+
> edit_post GET /posts/:id/edit(.:format) posts#edit
|
186
|
+
|
187
|
+
> post GET /posts/:id(.:format) posts#show
|
188
|
+
|
189
|
+
> PATCH /posts/:id(.:format) posts#update
|
190
|
+
|
191
|
+
> PUT /posts/:id(.:format) posts#update
|
192
|
+
|
193
|
+
> DELETE /posts/:id(.:format) posts#destroy
|
194
|
+
|
195
|
+
> users GET /users(.:format) users#index
|
196
|
+
|
197
|
+
> POST /users(.:format) users#create
|
198
|
+
|
199
|
+
> new_user GET /users/new(.:format) users#new
|
200
|
+
|
201
|
+
> edit_user GET /users/:id/edit(.:format) users#edit
|
202
|
+
|
203
|
+
> user GET /users/:id(.:format) users#show
|
204
|
+
|
205
|
+
> PATCH /users/:id(.:format) users#update
|
206
|
+
|
207
|
+
> PUT /users/:id(.:format) users#update
|
208
|
+
|
209
|
+
> DELETE /users/:id(.:format) users#destroy
|
210
|
+
|
211
|
+
> GET / books#index
|
212
|
+
|
213
|
+
> about GET /about(.:format) home#about
|
214
|
+
|
215
|
+
> login GET /login(.:format) users#login
|
216
|
+
|
217
|
+
> users_create POST /users/create(.:format) users#create
|
218
|
+
|
219
|
+
> rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
|
220
|
+
|
221
|
+
> rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
|
222
|
+
|
223
|
+
> rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
|
224
|
+
|
225
|
+
> update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
|
226
|
+
|
227
|
+
> rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
|
228
|
+
|
119
|
-
|
229
|
+
> ec2-user:~/environment/google_books_API/book_app (master) $
|
230
|
+
|
231
|
+
|
232
|
+
|
120
|
-
|
233
|
+
の様になっています。
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
121
|
-
|
239
|
+
エラーによると、paramsが取得できていません。
|
122
|
-
|
240
|
+
|
241
|
+
|
242
|
+
|
123
|
-
この場合、どうすればビューからコントローラに
|
243
|
+
この場合、どうすればビューからコントローラに、選択したオブジェクトを渡せますか?
|
244
|
+
|
245
|
+
目的はDBに保存することです。手法が間違っていたら他の方法での実装方法を教えていただけますか?
|
3
回答が得られなかったので、英語のエラーを日本語に修正しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails
|
1
|
+
Rails ビューからコントローラへparamsで値を渡せません。:ParameterMissingエラーが出ます。
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
RailsでGoogleBook APIを取得して、表示
|
7
|
+
RailsでGoogleBook APIを取得して、表示をしたいです。
|
8
8
|
|
9
9
|
|
10
10
|
|
2
画像を削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
RailsでGoogleBook APIを取得して、表示するシステムを作っています。
|
8
8
|
|
9
|
-
|
9
|
+
|
10
10
|
|
11
11
|
|
12
12
|
|
@@ -46,9 +46,11 @@
|
|
46
46
|
|
47
47
|
このように記載しています
|
48
48
|
|
49
|
-
|
49
|
+
ビューでは、
|
50
50
|
|
51
|
-
|
51
|
+
APIで種痘したデータも表示できています。
|
52
|
+
|
53
|
+
|
52
54
|
|
53
55
|
|
54
56
|
|
1
コードが見にくいのでタグで囲みました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails
|
1
|
+
Rails ActionController::ParameterMissingエラーが出ます。
|
test
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
ここに質問の内容を詳しく書いてください。
|
6
5
|
|
6
|
+
|
7
|
-
R
|
7
|
+
RailsでGoogleBook APIを取得して、表示するシステムを作っています。
|
8
8
|
|
9
9
|
Railsは初心者です。
|
10
10
|
|
@@ -19,6 +19,8 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
ビューは
|
22
|
+
|
23
|
+
```Rails
|
22
24
|
|
23
25
|
<%= @books.each do |book| %>
|
24
26
|
|
@@ -40,6 +42,8 @@
|
|
40
42
|
|
41
43
|
<% end %>
|
42
44
|
|
45
|
+
```
|
46
|
+
|
43
47
|
このように記載しています
|
44
48
|
|
45
49
|
表示もできています。
|
@@ -48,7 +52,7 @@
|
|
48
52
|
|
49
53
|
|
50
54
|
|
51
|
-
検証すると
|
55
|
+
GoogleDeveloper ツールで検証すると
|
52
56
|
|
53
57
|
![イメージ説明](30eb51097704386a8c181987fc18f9e1.png)
|
54
58
|
|
@@ -78,6 +82,8 @@
|
|
78
82
|
|
79
83
|
|
80
84
|
|
85
|
+
```Rails
|
86
|
+
|
81
87
|
# GET /books/new
|
82
88
|
|
83
89
|
def new
|
@@ -88,9 +94,13 @@
|
|
88
94
|
|
89
95
|
|
90
96
|
|
97
|
+
```
|
98
|
+
|
91
99
|
ストロングパラメータで
|
92
100
|
|
93
|
-
|
101
|
+
```Rails
|
102
|
+
|
103
|
+
|
94
104
|
|
95
105
|
def book_params
|
96
106
|
|
@@ -100,12 +110,12 @@
|
|
100
110
|
|
101
111
|
|
102
112
|
|
113
|
+
```
|
114
|
+
|
103
115
|
のように記載しています。
|
104
116
|
|
105
|
-
DBのカラムにあるのは間違いないのですが、それ以前にparamsが取得できていません。
|
117
|
+
permit以下はDBのカラムにあるのは間違いないのですが、それ以前にparamsが取得できていません。
|
106
118
|
|
107
119
|
ビューから取得できていません。
|
108
120
|
|
109
|
-
|
110
|
-
|
111
|
-
|
121
|
+
この場合、どうすればビューからコントローラに値を渡せますか?
|