gorter9
1
I trying to sort my posts by month at the way railscasts tells
http://media.railscasts.com/videos/029_group_by.mov
I only got the undefinded method error that beginning_at_month doesn’t
exists
undefined method `beginning_of_month’ for Time:Class
why is beginning_at_month an undefined method it’s also in the api
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html#M000597
gorter9
2
On 22 Jan 2008, at 10:30, GA Gorter wrote:
It’s an instance method (ie Time.now.beginning_of_month) but from the
error message it looks like you did Time.beginning_of_month
Fred
Okay i got an idea what was wrong
now it is
def archieven
@blogs = Blog.find(:all, :order => ‘created_at, id’)
@weblog_months = @blogs.group_by {|t| t.created_at.beginning_of_month
}
end
thanks for your help Frederick
gorter9
4
For that it works but now i have not the same result as in the railscast
in my controller
def archieven
@blogs = Blog.find(:all)
@weblog_months = @blogs.group_by {Time.now.beginning_of_month }
end
the view
<% @weblog_months.each do |month, blogs| %>
<%= month.strftime('%b') %>
<% for @blog in blogs %>
<%= link_to @blog.title, :controller =>'weblog', :action => 'show',
:id => @blog %>
<% end %>
<% end %>
The problem is that when i post a new post in another month it also
comes into the old month
there are no archives like into the railscast
On 22 Jan 2008, at 11:59, GA Gorter wrote:
For that it works but now i have not the same result as in the
railscast
in my controller
def archieven
@blogs = Blog.find(:all)
@weblog_months = @blogs.group_by {Time.now.beginning_of_month }
end
What you want to do is group_by {|blog|
blog.created_at.beginning_of_month} (assuming created_at is the
relevant date)
Fred