I'm quite new to rails and have been trying to work this out all night with no luck.
I have created 3 models:
business_hours belongs_to businesses which belongs_to users
user has_one business which has_many business_hours
First of all when you use belongs_to method don't use
s at the end of the word:
business_hours belongs_to business which belongs_to user.
Now create a migration:
rails generate migration migration_name
And in migration add columns:
class MigrationName < ActiveRecord::Migration def change add_column :business_hours, :business_id, :integer add_column :businesses, :user_id, :integer end end
rake db:migrate. That's it.