Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:10:25+00:00 2026-06-04T20:10:25+00:00

Im trying to figure out how to have data from multiple models show up

  • 0

Im trying to figure out how to have data from multiple models show up on the same calendar in my view. Right now it’s showing birthdays, but i would love to add anniversaries & holidays as well (which are currently just lists in view).. *stripped unnecessary formatting for clarity

https://github.com/watu/table_builder

users/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>

Models

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:10:28+00:00Added an answer on June 4, 2026 at 8:10 pm

    There’s nothing about a view that keeps it from using data from other models. You just have to make sure that the controller action passes it to the view somehow. You’re currently passing one @date object and one @user object; if you want other objects you should set those as well. I advise you to make those objects accessible via the @user object, which is to say that you should create instance methods for a User so that you can access them in a view

    class User
    
      def birthdays
        ...
      end
    
      def anniversaries
        ...
      end
    
      def holidays
        ...
      end
    end
    

    And then in your view, you can simply call @user.birthdays etc, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure out a way to tag several methods from
Hello I am trying to figure out how to get data from my worker
I'm trying to figure out how to have a short, one line conditional statement.
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out why and how to use performSelector. I
I'm trying to figure out how I can have a comment header automatically added
I am trying to figure out an easy way to have a password protected
I'm trying to figure out what version of Crystal Reports I have. It's the
I am trying to figure out how to create 3 divs and have them
I'm trying to figure out the logic for creating tasks that have dependencies. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.