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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Jan 2008, at 10:30, GA Gorter wrote:> > 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> http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html#M000597 > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 } > endWhat you want to do is group_by {|blog| blog.created_at.beginning_of_month} (assuming created_at is the relevant date) Fred> > > > 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 > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---