如何从查询中获取值并在Rails上将值加1 [英] How do I get a value from query and add the value by 1 on Rails
本文介绍了如何从查询中获取值并在Rails上将值加1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我非常感谢对这个简单问题的任何回复。
Hi, I really appreciate any respond for this simple question.
test = Model.find_by_sql("SELECT number FROM tbl_one LIMIT 1").each do |a|
p = a('number')
puts p
end
看,我的意思是,在将值存储到'p'之后,我如何将'p'值加1.
Look, I mean, after store a value to 'p', how do I add the 'p' value by 1.
puts p + 1
我试了但是不起作用。基于我所看到的,'p'并没有真正存储价值,但我不确定。无论如何,我是Ruby和Rails的新手
任何解决方案?
谢谢。
I tried it but doesn't work. Based on what I saw, the 'p' doesn't really store the value, but I don't really sure. Anyway, I'm new on Ruby and Rails
Any solution?
Thanks.
推荐答案
Ups!
抱歉,我的错误......我找到了它!
Ups!
Sorry, my mistake.. I found it!
p = a('number').to_i
然后我可以轻松地将值加1 ..
Then I can add the value by 1 easily..
这篇关于如何从查询中获取值并在Rails上将值加1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文