ruby on rails - wrong return value from service object -
i have controller use connection class (i made code simpler illustrate problem):
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 |x| case when (@obj.year > 1) && (@obj.day != 5) break "result case1: #{@obj.day}" when (@obj.year > 1) && (@obj.day == 5) @obj.update_attributes(day: 6) break "result case2 #{@obj.day}" end end return "#{@result}" end end the @flow object matches case 2 (day: 5), flash shows:
result case1: 6
when test connection class in console, return value correct.
maybe miss basic concept, thanks.
you're modifying object first time call connect (update_attributes(day: 6)), other case second time call it. if want call once, save return value in new variable , send flash.
Comments
Post a Comment