开发者

NoMethodError: Trying to call a model from a controller

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜