I'm able to get a model Post to be working properly for has_many and accepts_nested_attributes_for model Category. However, I want to limit a post to have only 1 category, which is where I'm failing. Here is the revised code:
# post.rb
has_one :category_tag, :dependent => :delete
has_one :category, through: :category_tag
accepts_nested_attributes_for :category_tag
# posts_controller.rb
def new
@post = Post.new
@post.category_tag.build
end
And ^ there is the problem: undefined method 'build' for nil:NilClass
It worked fine when I was using has_many :category_tags in the model and @post.category_tags.build
TIA