我有一个使用 Connection 类的控制器(我简化了代码来说明问题):
class InvoicesController < ApplicationController
def connect
@flow = Flow.new(year: 2010, month: 10, day: 5)
@con = Connection.new(@flow)
@con.connect
flash.now[:error] = "#{@con.connect}"
end
end
class Connection
def initialize(obj)
@obj = obj
end
def connect
@result = [1].each do |x|
case
when (@obj.year > 1) && (@obj.day != 5)
break "result from case1: #{@obj.day}"
when (@obj.year > 1) && (@obj.day == 5)
@obj.update_attributes(day: 6)
break "result from case2 #{@obj.day}"
end
end
return "#{@result}"
end
end
该@flow
对象匹配案例 2(第 5 天),但闪存显示:
result from case1: 6
当我在控制台中测试 Connection 类时,返回值是正确的。
也许我错过了一些基本概念,谢谢。