Hi, I have a model, Day, and the table, ''days'', contains 10,000 day records each with a field, ''date'', which has a ruby date object matched to a mysql date type, YYYY-MM-DD. I would like my controller to paginate Day by day.date.year. How do I do this? In other words, on each page, I want EITHER 365 records or 366 depending on whether or not it is a leap year--I want all of the days for a single year displayed on each page. Any idea how to accomplish this? SHW -- 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 -~----------~----~----~----~------~----~------~--~---
I did this recently to paginate by month. Wasn''t too hard as I recall. Just put the year into the route /:controller/:action/:year Or something similar. Then you can do: Day.find_by_year(params[:year]) Then just create links to each year, or what I did is something like <%= link_to :action => thesameaction, :year => params[:year] + 1 %> I didn''t do the plus 1 thing, I did next_month or something. But it''s doable. Sam Woodard wrote:> Hi, > > I have a model, Day, and the table, ''days'', contains 10,000 day records > each with a field, ''date'', which has a ruby date object matched to a > mysql date type, YYYY-MM-DD. I would like my controller to paginate Day > by day.date.year. How do I do this? In other words, on each page, I > want EITHER 365 records or 366 depending on whether or not it is a leap > year--I want all of the days for a single year displayed on each page. > > Any idea how to accomplish this? > > SHW > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can somebody explain this explanation to me? What does it mean to "add to route". Sam -- 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 -~----------~----~----~----~------~----~------~--~---
You have to edit config/routes.rb. Read the section on routing in AWDWR. This is one of the sections that made me go "wow". You need to know it if you''re going to develop in Rails. Sam Woodard wrote:> Can somebody explain this explanation to me? What does it mean to "add > to route". > > Sam > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I added "map.connect '':controller/:action/:year''" to the routes, but I can''t get a find_by_year method in the Day model. Year is not a field in the table, date is. The year is accessed through date.year. How do I create a model variable so that I can create a year class variable and ruby will then create for me a find_by_year method for the model??? -- 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 -~----------~----~----~----~------~----~------~--~---