Torihaji's Growth Diary

Little by little, no hurry.

Railsのbuildとかcreate!の引数に文字列は渡してはいけません。

はじめに

しっかり理解してればつまらないこと。

これを機に理解しました。

前にもやったことがあったのでエラー文見てピンときました。

戒めのためです。

現場

tweet = current_api_v1_user.tweets.create!(tweet_params[:content])

と書いたら

#<ArgumentError: When assigning attributes, you must pass a hash as an argument, String passed.>

と言われました。

hashを渡してね、文字列渡しているよ

ということ。

解決

 tweet = current_api_v1_user.tweets.create!(content: tweet_params[:content])

createに渡す引数をhashにしましょう。

以上です。

終わりに

このエラー文見るの2回目だったのですぐ気づきました。