Answer the question
In order to leave comments, you need to log in
It was necessary to use 2 models in the form (what is better to use reform or nested_atributes) what does it depend on?
reform to use when you need additional form validation logic?
It is also not clear that specific attributes are usually indicated in the manual for it.
class AlbumForm < Reform::Form
include Composition
property :id, on: :album
property :title, on: :album
property :songs, on: :cd
property :cd_id, on: :cd, from: :id
end
Answer the question
In order to leave comments, you need to log in
If the logic is simple and no extensions are expected, then use nested_attributes, because they are already there.
If the logic is complex, then the next question is - should such a complex piece be 1-2 in the system? If so, create an app/services folder (app/interactors) and put the AlbumSaver class there. And the app/form_objects folder with the AlbumUpdateForm class. And call AlbumSaveForm in AlbumSaver.
If you have a lot of places where you need very complex forms, then add some form management gem to the previous approach
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question