You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below produces this error when assigning the parent to the new resource using the :through parameter that points to a method in the controller.
@subscription.member should have been assigned, instead of @subscription.current_member.
There are a few workarounds to this. First, there's the inverse_of parameter on associations, so it's possible to find the reflection and get the proper name. Additionally, when inverse_of is present, you probably don't have to assign the parent manually but rather use build_#{resource_name}.
Another option is to add a new inverse_of option to load_and_authorize_resource method, where we can explicitly specify the parent name.
Steps to reproduce
The code below produces this error when assigning the parent to the new resource using the
:through
parameter that points to a method in the controller.Expected behavior
@subscription.member
should have been assigned, instead of@subscription.current_member
.There are a few workarounds to this. First, there's the
inverse_of
parameter on associations, so it's possible to find the reflection and get the proper name. Additionally, wheninverse_of
is present, you probably don't have to assign the parent manually but rather usebuild_#{resource_name}
.Another option is to add a new
inverse_of
option toload_and_authorize_resource
method, where we can explicitly specify the parent name.Actual behavior
System configuration
Rails version: 7.0.3
Ruby version: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin20]
CanCanCan version: 3.3.0, 3.4.0
The text was updated successfully, but these errors were encountered: