views:

138

answers:

1

I'm using ActiveScaffold to create an Admin UI.

  • I have two models: Post and Comments.
  • A Post has-many Comments, and a Comment belongs-to a post.
  • There's a validates_presences_of :text validation the Comment model.

The problem is that when I create a new Post from the Admin UI without creating a new Comment in the subform, ActiveScaffold complains about the validation. I can create the Post if I also create a Comment associated with it, which is not what I Want.

I can create a new Post manually from script/console.

What gives?

A: 

Maybe ActiveScaffold things that you want to create at least one Comment per Post. I've encountered this problem with a has-one… it seems like ActiveScaffold would be smart enough in the has-many case, but who knows.

Here's how I solved it for has-one (and is the UX I wanted anyway):

# if post has-one attachment
active_scaffold :post do |config|
  config.columns[:attachment].form_ui = :select
end

of course :select won't make sense for comments, but you could look into a similar UI change, telling it to not try to stick the form inline (if that is indeed what's happening)

John