I would like to limit the number of model Objects a user can create. I've tried the below but it is not working. I understand some changes have happened in rails 3.1 and not sure how to accomplish this now.
class User < ActiveRecord::Base
has_many :things, :limit => 5, :dependent => :destroy # This doesn't work
end
class Things <ActiveRecord::Base
belongs_to :user
end
Try something like this:
Edit: updated for Rails 3
It did not work on Rails 3.2.1. Count always equals to
0
. I have replaced it withself.user.things.size
and now it works.