0

i am new to ruby and nanoc. I am trying to sort articles based on time. So I get more accurate results on my blog.

This is what I am using in my sorted_articles_time.rb file under /helpers/

def sorted_articles_time
  articles.sort_by do |a|
    attribute_to_time(a[:time])
  end.reverse
end

But then I get the error

NoMethodError: private method `sorted_articles_time' called for #<Nanoc::Site:0x007fd93b0a3f40>

What am I doing wrong ? And is there a way to overwrite the existing sorted_articles method ?

Thanks

UPDATE: I already have it initiated in the rake file. So I think my rake file is fine here.

time1 = Time.new
@time =  time1.inspect
user1758162
  • 171
  • 8

2 Answers2

2

Are you calling @site.sorted_article_times? If so, leave off the @site part. Helpers are intended to be called as functions, not as methods on @site.

Denis Defreyne
  • 2,213
  • 15
  • 18
  • Ah, right. But now that i removed that. I get an error `ArgumentError: comparison of NilClass with Time failed` – user1758162 Dec 12 '12 at 21:38
  • Then I am guessing some article’s `:time` attribute is nil. – Denis Defreyne Dec 13 '12 at 06:30
  • Ah i got it. Parsed a new time object and sorted the articles based on that. Thanks. If you got time. can you help me answer this - http://stackoverflow.com/questions/13866141/how-to-generate-pages-for-each-tag-in-nanoc Thanks :) – user1758162 Dec 13 '12 at 18:30
-3

Use a scrope from your model. Check this activeactive_record_querying this is the best place to sort your articles.

Jean
  • 5,201
  • 11
  • 51
  • 87