So, I'm fairly new to Rails and I'm stuck due to my model's complexity.
I have a Developer
model, a Township
model and a Project
model and their contents are as follows:-
Developer.rb
Class Developer < ApplicationRecord
has_many :townships,
has_many :projects, through: :townships
accepts_nested_attributes_for :township
end
Township.rb
Class Township < ApplicationRecord
belongs_to :developer
has_many :projects
accepts_nested_attributes_for :project
end
Project.rb
Class Project < ApplicationRecord
belongs_to :township
end
I want to create projects such as follows:-
project = Developer.create(
{
name: 'Lodha',
township_attributes: [
{
name: 'Palava',
project_attributes: [
{
name: 'Central Park'
},
{
name: 'Golden Tomorrow'
}
]}
]})
Any ideas as to how can I accomplish this? I also need to understand the strong params whitelisting required in the DeveloperController
.