我正在尝试运行一种方法,如果存在(表 Hashtag 列标签)标签,它会将视图计数更新 1。否则它将创建一个默认视图计数为 0 且标签为 @hashtag 已清理的新行。
哈希日志.rb
def self.create_hashlog(hashtag) #enters hashtag into the log table, without #.
@hashtag_scrubbed = hashtag
# Hashlog.find_or_create_by_tag(@hashtag_scrubbed)
taglog = Hashlog.find_or_create_by_tag(@hashtag_scrubbed) do |t|
t.count = 0
end
taglog.count += 1
taglog.save!
end
错误
Completed 500 Internal Server Error in 772ms
NoMethodError (undefined method `+' for nil:NilClass):
app/models/hashlog.rb:24:in `create_hashlog'
app/controllers/hashtags_controller.rb:32:in `create'