컨트롤러에서 정확히 산술 연산을 수행합니까?레일스에 컨트롤러를 추가하는 방법은 무엇입니까?
내가 그러나이
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
은 정확한 루비 오류가 무엇입니까? – emaillenin