And then when the user POSTs directly to your create action, your
maximum advert limit is for naught. It might *seem* to make more sense
to put this in the create action, where the advertisement is actually
getting persisted to the DB or whathaveyou, but even then this seems
like domain specific logic that really should go in your model. (I
know I'm getting waaaay ahead of myself here, but what if this one
specific controller ends up not being the only place you'll have users
be able to create adverts from? More importantly I guess, keeping this
in the model makes everything *much* easier to spec). A simple
"maxed_adverts?" method and an "create_avert" method in the model
which checks the prior would do nicely.
maxed_adverts? looks like something that checks if the user has maxed
their advert limit. Maybe it looks like "def maxed_averts?;
averts.count >= 3; end"? Maybe it looks different.
Call it like you would any other method on your models... I guess it
helps when your starting out to always remember that Rails "models"
are nothing more than instances of Ruby classes which *usually*
descend from ActiveRecord::Base. Nothing magical about them but the
magic you give them.