服务抛出“未定义的方法”错误

时间:2018-08-17 00:33:17

标签: ruby-on-rails

我可能缺少明显的东西,但是我无法弄清楚问题出在哪里。我有一个名为GoodMorning的服务(app / services / good_morning.rb)

class GoodMorning

    def self.dawn(user)
        if user.goal_days.where("day = ?", Date.today).count == 0
            user.goals.each do |goal|
                if goal[time.strftime("%A")] == true
                    GoalDay.create(goal_id: goal.id, body: goal.body, target: goal.target, actual: 0, day: Date.today)
                end
            end
            session[:sun] = true
        end
    end
end

然后在名为Clearing的控制器(app / controllers / clearing_controller.rb)中,我将其称为:

def index
    @user = current_user
    @goals_today = GoalDay.where("user_id = ? AND day = ?", @user.id, Date.today)
    if session[:sun] == true
      if @goals_today.count == 0
        session[:sun] = false
      end
    else
      GoodMorning(@user).dawn
    end
end

我收到以下错误:

  

#的未定义方法“ GoodMorning”

感谢您对我所缺少的任何帮助!我重新启动了服务器等。

1 个答案:

答案 0 :(得分:1)

尝试...

GoodMorning.dawn(@user)