infoMore than 5 years have passed since last update.
Railsでハマった所メモ(逐次更新)
Last updated at Posted at 2018-08-07
form_tag で送った input の値が params として受け取れない(2018/8/7)
状況
- フォームとボタンを用いてデータベースに新規登録したいが、何も登録されずにプロセスが完了してしまう
考え方
-
<%= form_tag %>
で指定した先のアクションで問題が起こっている
- 条件分岐させると
@user.save
が false となっている
-
@user = User.new(hoge: params[:fuga])
のうちどこかがおかしい
- しかしエラーは起こっていないので
params[:fuga]
が正しく受け取られていなさそう
- ビューにおける
<input>
タグの記述を再確認
原因
-
<input>
タグにおいて name="fuga"
とすべきところを content="fuga"
としていた
参考
- Rails5以降は
form_tag
ではなく form_with
を使うことが推奨されているみたい。こちらを使いましょう。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
What you can do with signing up