I'm trying to create a nested path for a show action of a nested resource
user.rb
has_many :fan_receives, as: :fanzone_owner, class_name: "FanActivity"
fan_activity.rb
belongs_to :fanzone_owner, polymorphic: true
In my routes.rb
match ":fanzone_owner_id/posts/:id", to: "fan_activities#show", via: :get
The path works, but the fanzone_owner_id could be anything. For an example,
example.com/1/fan_activities/2 works
example.com/2/fan_activities/2 also works
example.com/anythingatall/fan_activities/2 also works
I would like to make it so the fanzone_owner_id of the url must match the foreign key of the fan_activity, otherwise we redirect to 404.
Would I do this with validation check of the url in the controller? I'm not sure if this approach is correct