calendar_helper highlight


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Model:
  2. def starts_on
  3. Date.civil(self.starts_at.year, self.starts_at.month, self.starts_at.day)
  4. end
  5.  
  6. def ends_on
  7. Date.civil(self.ends_at.year, self.ends_at.month, self.ends_at.day)
  8. end
  9.  
  10. Migration:
  11. class CreateEvents < ActiveRecord::Migration
  12. def self.up
  13. create_table :events do |t|
  14. t.column :name, :string
  15. t.column :description, :text
  16. t.column :starts_at, :datetime
  17. t.column :ends_at, :datetime
  18. end
  19. end
  20.  
  21. def self.down
  22. drop_table :events
  23. end
  24. end
  25.  
  26. View:
  27. <%=
  28. calendar(:year => Date.today.year, :month => Date.today.month) do |d|
  29. cell_text = "#{d.mday}<br />"
  30. cell_attrs = {:class => 'day'}
  31. @events.each do |e|
  32. if e.starts_on == d || ( e.starts_on <= d && e.ends_on >= d )
  33. cell_attrs[:class] = 'specialDay'
  34. end
  35. end
  36. [cell_text, cell_attrs]
  37. end
  38. %>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.