开发者

NoMethodError: Trying to call a model from a controller

开发者 https://www.devze.com 2023-03-07 03:01 出处:网络
I do need some help with this error: NoMethodError in PostsController#checkin undefined method `hasToday\' for #

I do need some help with this error:

NoMethodError in PostsController#checkin undefined method `hasToday' for #

Controller:

def checkin
    @date = DateTime.parse(params[:day])
    if (Post.hasToday(@date))
end

Model:

class Post < ActiveRecord::B开发者_如何转开发ase

  scope :created_on, lambda {|date| {:conditions => ['DATE(created_at) = ?', date.to_s(:db)]}}

  def hasToday(date)
    self.created_on(date).count > 0 ? true : false
  end

end


try this in your modal

    def self.hasToday(date)
         self.created_on(date).count > 0 ? true : false
    end
0

精彩评论

暂无评论...
验证码 换一张
取 消