您究竟在控制器中執行算術運算?如何在Rails中添加控制器?
我已經試過這
def choose
rand_id = rand(Gif.count)
@gif1 = Gif.first(:conditions => [ "id >= ?", rand_id])
@gif2 = Gif.first(:conditions => [ "id >= ?", rand_id])
if @gif1.id == @gif2.id
@gif2 = Gif.first(:order => 'Random()')
end
total = @[email protected]
number_one = @gif1.votes/total*100
number_two = @gif2.votes/total*100
@gif1.update_attribute(:votes, number_one)
@gif2.update_attribute(:votes, number_two)
end
class Gif < ActiveRecord::Base
before_save :default_agree_count
def default_agree_count
self.agree = 1
self.votes = 1
end
VALID_REGEX = /http:\/\/[\S]*\.gif$/
attr_accessible :link, :votes, :agree
acts_as_votable
validates :link, presence: true, format: {with: VALID_REGEX}, uniqueness: {case_sensitive: false}
end
然而,它說,+,/,*都是未知的運營商。我也嘗試過這樣做@ gif1.agree ='@ gif1.votes + 1'有和沒有'。有任何想法嗎?
謝謝!
投票的數據類型是什麼? – emaillenin
這是一個整數類型 – user3340037
什麼是確切的Ruby錯誤? – emaillenin