11175
(-- --)
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
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
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
11175
(-- --)
3
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| %>
<h1><%= month.strftime('%b') %></h1>
<% for @blog in blogs %>
<%= link_to @blog.title, :controller =>'weblog', :action => 'show',
:id => @blog %><br>
<% 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
11175
(-- --)
4
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
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