Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

def display_fields / form_fields do not cover detach #2403

Closed
FLX-0x00 opened this issue Jan 23, 2024 · 0 comments · Fixed by #2415, #2436 or #2459
Closed

def display_fields / form_fields do not cover detach #2403

FLX-0x00 opened this issue Jan 23, 2024 · 0 comments · Fixed by #2415, #2436 or #2459
Assignees
Labels
Bug Something isn't working

Comments

@FLX-0x00
Copy link

If you declare display_fields' and form_fields' like this

def display_fields
 field :title as: :text
 field :users as: :has_and_belongs_to_many
end

def form_fields
 field :title, as: :text
 field :users as: :has_and_belongs_to_many
end

You cannot detach a user resource because you get the error: use_resource for NIL class. This may be because the DELETE request for the association does not have the field. To "fix" this, you need to declare the "fields" method only with the association, such as

def fields
 field :users as: :has_and_belongs_to_many
end

With the "fields" method, the detach will work. You may need to check that a detach is also covered in "form_fields" so that you do not have to declare the "fields" method just for the detach. We are trying to make the code cleaner and easier to read by separating the different views into the corresponding field methods. It would be nice to not have the "fields" method for some resources and use the form/display fields completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: Done
3 participants