Right, having been playing around with this, it seems that the way to make this type of validation is pretty straight forward. All it requires is that the nested resource be built in relation to it's project, this forces the :parent_id to be passed through to the validation as expected.
In the case of this toy example, that means that the create action has to look something like:
@project = Project.find_by(id: params[:project_id])
@task = @project.tasks.build(model_params)
It should be noted that because of Rails not supporting generation of nested resources from the command line, the way that the scaffold generated controllers handle creation is by Model.new(model_params)
and then saving, this doesn't seem to pick up the :parent_id
in time for the validation and so will need changing as above (in terms of the parent).