开发者

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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜