Rails 3: Dependent => :deny or similar?
I have a model "location", which has many "courses"
If I destroy a location, I'd like the destroy request to be rejected unless there are no relationships between the location and any courses. I assume there's some pretty concise way of doing this, but I can't fin开发者_如何学Cd anything.
Soo...what's the most elegant/simple/concise way of enabling this sort of functionality?
in Location...
before_destroy do |l|
return false unless l.courses.nil?
end
精彩评论