【发布时间】:2013-12-02 08:55:03
【问题描述】:
class Post < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :posts
end
我的问题是如何通过迭代删除构建的资源? 可以说我有许多 BUILT (尚未在数据库中)帖子的用户。 如何删除特定帖子? 我试过这种方法,但不行:
@user.posts.each {|post| post.delete if post.content.nil? }
当然是通过posts,执行'delete'方法,但是所有的posts都在开始的地方......
【问题讨论】:
标签: ruby-on-rails ruby