Skip to content

Instantly share code, notes, and snippets.

@shreyas-satish
Created July 4, 2011 07:40
Show Gist options
  • Save shreyas-satish/1063015 to your computer and use it in GitHub Desktop.
Save shreyas-satish/1063015 to your computer and use it in GitHub Desktop.
No Method Error while using modules in Rails Controllers
#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