# Requiring User to Select Categories -- (on Post Creation)

**URL:** <https://www.ruby-forum.com/t/requiring-user-to-select-categories-on-post-creation/133403>\
**Category:** Rails\
**Created:** [March 31, 2008, 9:55am UTC](https://www.ruby-forum.com/t/requiring-user-to-select-categories-on-post-creation/133403 "2008-03-31T09:55:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [March 31, 2008, 9:55am UTC](https://www.ruby-forum.com/t/requiring-user-to-select-categories-on-post-creation/133403/1 "2008-03-31T09:55:18Z")

</div>

Hello,

I’m having trouble with validation. I want to require the user to select  
a category before a post is successfully created.

I’m using has\_many :through for posts and categories as follows:

class Post \< ActiveRecord::Base  
has\_many :categorizations  
has\_many :categories, :through =\> :categorizations  
end

class Categorization \< ActiveRecord::Base  
belongs\_to :category  
belongs\_to :post  
end

class Category \< ActiveRecord::Base  
has\_many :categorizations  
has\_many :posts, :through =\> :categorizations  
end

I’ve tried validates\_presence\_of :categorizations in the Post model, but  
the application simply saves it without verifying that the user selected  
a checkbox.

Any ideas what I can do?
