controller.rb
if @object.save
Post.method_name(@object)
end
post.rb
def self.method_name(object)
post_id = 1
p = Post.new
p.post_id = post_id
p.save
end
当执行Post.method_name(@object)
时,即使我看不到任何错误,我也无法在表中看到新帖子...
答案 0 :(得分:0)
解决方案:
我收到以下错误
Validation failed: Post type is not included in the list
当我使用p.save!
归因于validates :post_type, :presence => true, :inclusion=> { :in => @allowed_post_types }
所以当我添加我使用的帖子类型@allowed_post_types
问题已解决