Rails app has trouble with inter-model saving

前端 未结 2 713
无人共我
无人共我 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.

    0 讨论(0)
  • 2021-01-29 05:25

    By inspection, the offending line appears to be:

    self.robots_tags.robots_meta = tag
    

    You should iterate over self.robots_tags instead, with something like:

    self.robots_tags.each do |robot_tag|
      robot_tag.robots_meta = tag
    end
    
    0 讨论(0)
提交回复
热议问题