Rails app has trouble with inter-model saving

前端 未结 2 714
无人共我
无人共我 2021-01-29 04:37

I\'m working on an app that downloads meta tags from websites and saves then. The downloading happens in a model called Site. I\'d like to save off the downloaded

2条回答
  •  抹茶落季
    2021-01-29 05:24

    The problem is here:

    self.robots_tags.robots_meta = tag
    

    self.robots_tags is a collection of objects defined by has_many :robots_tags, and you're attempting to assign a specific attribute to that entire collection. You can't do this. If you want to assign to an attribute on a specific object, you have to either iterate over the collection, or select a specific object from the collection via first or last or any of the other Enumerable methods.

提交回复
热议问题