Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 用新排序问题替换旧排序问题的方法_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby 用新排序问题替换旧排序问题的方法

Ruby 用新排序问题替换旧排序问题的方法,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,语法错误:(irb):275:语法错误,意外“}” (irb):280:语法错误,意外的tIDENTIFIER,应为“:” …新建排名。推送(a)旧排名。删除(i):下一个} ... ^ (irb):280:语法错误,意外的“:”,应为“}” …h(a)旧排名。删除(i):下一个} ... ^ (irb):284:语法错误,意外的关键字\u end,应为“}” 从lib/rai

语法错误:(irb):275:语法错误,意外“}” (irb):280:语法错误,意外的tIDENTIFIER,应为“:” …新建排名。推送(a)旧排名。删除(i):下一个} ... ^ (irb):280:语法错误,意外的“:”,应为“}” …h(a)旧排名。删除(i):下一个} ... ^ (irb):284:语法错误,意外的关键字\u end,应为“}” 从lib/rails/commands/console.rb:44:in
start'
从lib/rails/commands/console.rb:8:in
start' 来自lib/rails/commands.rb:23:in
'
从脚本/rails:6:in
require' 来自脚本/rails:6:in`'

问题模型
在第一个#带有#索引的每个#中缺少“do”

    def replaceranked
        oldrankings = Question.where(:rank => [1,2,3,4,5])

        # Mocking the creation of a new top 5
        newrankings = Question.where(:id => [4,5,6,7,8])
        newrankings.each_with_index |a, i| 
            a.rank = i+
        end

        oldids = oldrankings.map{|a| a.id}
        newids = newrankings.map{|a| a.id}
        simlarities = oldids & newids

        oldrankings.each_with_index do |a, i| 
            if !(similarities.includes?(a.id))
                newrankings.push(a) 
                oldrankings.delete_at(i) 
            end
        end

        oldrankings.map{|a| a.rank = nil}
        updatedtopfive = newrankings | oldrankings
        updatedtopfive.map{|a| a.save}
    end
    Id:Integer
    Content:String
    Rank:Integer #Normally Null unless ranked in which case you'll have a rank of 1 to 5