LoginSignup
1
1

More 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"としていた
    • CSSの記法と混同していた

参考

  • Rails5以降は form_tag ではなく form_with を使うことが推奨されているみたい。こちらを使いましょう。
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1