I am new to rails and read this guide to get all the info so far.
I have a simple scenario and want to make sure whether or not my associations will work fine.
Scenario:
User
logs in -> sets up many groups
-> each group has many employees
User
model:
class User < ActiveRecord::Base
has_many :groups
end
Group
model:
class Group < ActiveRecord::Base
belongs_to :user
has_many :employees
end
Employee
model:
class Employee < ActiveRecord::Base
has_many :groups
belongs_to :group
end
Questions
- Will this work for the scenario I mentioned?
- I am confused about how to get all
Employees
under aUser
. What would be the code for that? - If I need typical CRUD for all these models then would would be in my Action? index/create/update/destroy? Can someone point me to a good guide on actions?