Created
July 4, 2011 07:40
-
-
Save shreyas-satish/1063015 to your computer and use it in GitHub Desktop.
No Method Error while using modules in Rails Controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/time_filter.rb | |
module TimeFilter | |
def today | |
where("created_at >= ?", Date.today) | |
end | |
end | |
# In Rails Console | |
>> include TimeFilter | |
>> Person.find(1).articles.today | |
>> [#article....] | |
# Successfully returns articles | |
--------------------------------------- | |
#In my controller | |
class ArticlesController < ApplicationController | |
include TimeFilter | |
def filter_by_today | |
@articles = Person.find(1).articles.today | |
end | |
end | |
#RETURNS ERROR | |
#NoMethodError in ArticlesController#filter_by_today | |
#undefined method `today' for #<Class:0xb65b2b54> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment