I want to limit the amount of records a user can add to the database.
I'm not sure of the 'Rails' way to go about this...
I am using Devise and thought of creating a custom validation method but you can't access current_user
from within a model and it isn't correct.
How can I do this from the controller and still return an error message to my users?
I had this
validate :post_count
def post_count
current = current_user.posts.count
limit = current_user.roles.first.posts.count
if current > limit
errors.add(:post, "Post limit reached!")
end
end
but it isn't the correct way to go about it as it would be hacky to get the current_user into the model