I am not really following up what is happening with the routes concern thing, but I just want to point out that using “def method” like the proposed solution introduces a chance of method conflict:
resources :posts do
Bam, now you are conflicting with https://github.com/rails/rails/blob/0dd24728a088fcb4ae616bb5d62734aca5276b1b/actionpack/lib/action_dispatch/routing/mapper.rb#L1414 and it can lead to a considerable amount of hair pulling. I don’t think there is a way for us to detect such conflicts (or is there a way to define a method_added hook in the object singleton class?). Besides, the fact that the current router implementation is a bunch of modules with many private methods (don’t get me started) just makes the chances of conflict higher.
Of the suggestions I have seen so far, I liked the lambda one the most. But then, I am a sucker for functional programming.