Use formtastic with ActiveAdmin create deep nested form
Closed this issue · 5 comments
Using Rails 6, I am designing an application for manage police fines.
A user can violate many articles, an article can have many letters and a letter can have many commas.
This is my implementations:
#models/fine.rb
class Fine < ApplicationRecord
has_many :violations
has_many :articles, through: :violations
has_many :letters, through: :violations
has_many :commas, through: :violations
end
#models/article.rb
class Article < ApplicationRecord
has_many :letters
has_many :violations
has_many :fines, through: :violations
end
#models/letter.rb
class Letter < ApplicationRecord
belongs_to :article
has_many :commas
has_many :violations
has_many :fines, through: :violations
end
#models/comma.rb
class Comma < ApplicationRecord
belongs_to :letter
has_many :violations
has_many :fines, through: :violations
end
#models/violation.rb
class Violation < ApplicationRecord
belongs_to :fine
belongs_to :article
belongs_to :letter, optional: true
belongs_to :comma, optional: true
end
When I print the Fine in pdf I need to show violations: articles, letters and commas.
I have some difficult creating form to compile the Fine with articles,letters,commas becouse is too deep.
I am using Active Admin, when I create new Fine I want to associate many violations.
Violation example:
Violation.new
=> #<Violation id: nil, article_id: nil, fine_id: nil, letter_id: nil, comma_id: nil, note: nil, created_at: nil, updated_at: nil>
How can I create a form (using Active Admin, who use Formtastic) to associate many violations to a Fine?
Example form: when create new Fine I want associate articles, letters and commas:
Example (with sample data):
Violation.new fine: fine, article: a, letter: a.letters.last, comma: a.letters.second.commas.last
=> #<Violation id: nil, article_id: 124, fine_id: 66, letter_id: 10, comma_id: 4, note: nil, created_at: nil, updated_at: nil>
@cristianogregnanin Can you post your question on StackOverflow? Getting things working in ActiveAdmin is sometimes tricky. Here we're a couple of maintainers and we can't find time to answer usage questions, I think a wider community can help you in StackOverflow!
Sorry, given its title I thought this issue had been posted on the ActiveAdmin repo 😅. I still think you might have more help in StackOverflow :)
Actually I now see that you posted the exact same thing on the ActiveAdmin repo 🤣.
@cristianogregnanin Can you post your question on StackOverflow? Getting things working in ActiveAdmin is sometimes tricky. Here we're a couple of maintainers and we can't find time to answer usage questions, I think a wider community can help you in StackOverflow!
Hi, I have posted on stackoverflow but I have no answer. I am not only person in the world with this problem, but I haven't found solutions
https://stackoverflow.com/questions/65370464/rails-6-design-database-for-polices-fines
I see your SO question is marked as solved, closing the issue.