pekorinko / review_check

0 stars 0 forks source link

既に検索されたことがある施設の場合は、検索される度に新たなPlaceのレコードに上書きする #68

Closed pekorinko closed 3 years ago

pekorinko commented 3 years ago

現状とこれからやること(その理由)

pekorinko commented 3 years ago

試したこと

def create_place Place.create( lrd: @lrd, place_name: @result[:place_name], address: @result[:address], star_ave: @result[:star_ave], ) end

## 上記を試した結果のエラー(既に検索したことがある施設で実施した)
- エラー内容:results_controller.rbの46行目`place_id = place.id`は定義されていないと怒られている
- 恐らくこのエラーが出ている原因は`place_data_scraper.rb`の`save_palce`メソッドの以下コードが原因(`place.present?`がtrue=Placeが既に存在する)際は`place_name`,`address`,`star_ave`を更新する)
- 上記箇所を原因として考えた理由としてはエラーメッセージで`NoMethodError (undefined method `id' for true:TrueClass):`となっている

【エラーの原因となっていると思しき箇所】→place_data_scraper.rbsave_palce` if place.present? return( place.update( place_name: @result[:place_name], address: @result[:address], star_ave: @result[:star_ave], ) ) end

【エラーの内容】 NoMethodError (undefined method `id' for true:TrueClass):

app/controllers/results_controller.rb:46:in `create'


![image](https://user-images.githubusercontent.com/61894818/118734760-fff91680-b879-11eb-9368-f8d8bbaa6e5b.png)

## 既に存在する施設の場合はレコードを上書きするコードを書く際に参考にした記事
- Railsドキュメント データベースを更新 https://railsdoc.com/page/model_update
## 新たに検索する施設に関しては上記のようにコードを書き換えたとしても問題なく動く
![image](https://user-images.githubusercontent.com/61894818/118735815-2f108780-b87c-11eb-924c-84df7d416a5c.png)
pekorinko commented 3 years ago
pekorinko commented 3 years ago

NoMethodError (undefined method `id' for true:TrueClass):の原因