Ok, so I have 4 models Users, Projects, Files, and ProjectsFiles
class User < ActiveRecord::Base
has_many :files
end
class Project < ActiveRecord::Base
has_many :projects_files
has_many :files, through: :projects_files
end
class File < ActiveRecord::Base
has_many :projects_files
has_many :projects, through: :projects_files
end
class ProjectsFiles < ActiveRecord::Base
belongs_to :project
belongs_to :file
end
When creating a project I want my form to display a list the user's files with checkboxes. The user will be able to check files they want to add to the project which should build a ProjectsFile for each checked file and destroy any ProjectsFiles that aren't checked. Is this possible with accepts_nested_attributes_for and fields_for? I've been trying several different things but I can't get it right. What's a good way to go about this? Is there a better way?