我试图弄清楚如何让来自多个模型的数据在我的视图中显示在同一个日历上。现在它正在显示生日,但我也很想添加周年纪念日和假期(目前只是列表中的列表).. *为了清晰起见,去除了不必要的格式
https://github.com/watu/table_builder
用户/show.html.erb
<% if @user.friends.any? %>
<h3>Upcoming Birthdays</h3>
<div id="calendar">
<h2 id="month">
<%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m") %>
<%=h @date.strftime("%B %Y") %>
<%= link_to ">", :month => (@date.end_of_month+1).strftime("%Y-%m") %>
</h2>
<%= calendar_for @friends, :year => @date.year, :month => @date.month do |calendar| %>
<%= calendar.head('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') %>
<%= calendar.day(:day_method => :dob) do |date, friends| %>
<%= date.day %>
<ul>
<% friends.each do |friend| %>
<li> <%= link_to h(friend.name), friends %><%= "\'s birthday"%></li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
<% end %>
<% if @user.holidays.any? %>
<h3>Upcoming Holidays</h3>
<% @user.holidays.each do |hld| %>
<td><%= hld.name %></td>
<td><%= hld.date %></td>
<% end %>
</tbody>
</table>
楷模
class User < ActiveRecord::Base
has_many :friends
has_many :user_holidays
has_many :holidays, :through => :user_holidays
has_many :anniversaries
class Holiday < ActiveRecord::Base
attr_accessible :name, :date
has_many :user_holidays
has_many :users, :through => :user_holidays
end
class UserHoliday < ActiveRecord::Base
attr_accessible :holiday_id, :user_id
belongs_to :user
belongs_to :holiday
end
class Anniversary < ActiveRecord::Base
belongs_to :user
attr_accessible :anniversary_date, :spouse_name, :anniversaries, :interest_ids
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
end