Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-plugins

ROR: has many relationships help


I am new to rails and i want to get some help regarding has many relationships.

I included the full calendar app from https://github.com/bokmann/rails3_fullcalendar into my new application.

I have a user model. I want all the users to have a one calendar each. Right now the calendar is same for all users.

I tried:

in user.rb

...
belongs_to :events

in events.rb

has_many :users

This did not work.

I did the same by creating calendar.rb but it still did not work

Any ideas?


Solution

  • I think you should read Rails Guides: http://guides.rubyonrails.org/association_basics.html a little bit more carefully.

    I guess what you probably want is Event and User instances to connect with each other using has_and_belongs_to_many or has_many :through

    After that, implementing a business logic where user attends to many events or an event has many users (attenders) is easy - I guess that is what you want, because you're bit unclear in your post. And a calendar is just a nice way to display events for a particular user.

    I hope this helps.