ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

Question regarding Update #869

Closed adamhoff closed 7 years ago

adamhoff commented 7 years ago

How do I make it so that whenever i update one of the days through edit, the day keeps its same position instead of appending to the end of the month? https://github.com/adamhoff/calendar

juancgarcia commented 7 years ago

It sounds like your days are being sorted by updated_at. If display order is important (and I'm guessing it is for a calendar app) you'll need to enforce that order yourself.

One option is to sort the list as you're displaying it in app/views/months/show line 3

<% @month.days.sort_by {|day| day.date}.each do |day| %>

Another option is to have the database do the sorting for you by using the ActiveRecord method .order() in your controller action instead of .all(). More info here: http://guides.rubyonrails.org/active_record_querying.html#ordering

AndyWhitley commented 7 years ago

@adamhoff Did this solve your issue?

adamhoff commented 7 years ago

Yes it did thank you!