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


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

class Categorization < ActiveRecord::Base
belongs_to :category
belongs_to :post

class Category < ActiveRecord::Base
has_many :categorizations
has_many :posts, :through => :categorizations

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs