如果你删除一个article,那么它关联的comments同样也会被删除。否则他们会在数据库中占据掉空间。Rails允许你用dependent属性,这是涉及到关联性中的一个属性来获取到这个。修改Article模型,app/models/article.rb 类似于下面:
classArticle < ActiveRecord::Base has_many :comments, dependent: :destroy validates :title, presence: true, length: { minimum: 5} end |
original text: http://guides.rubyonrails.org/getting_started.html#deleting-associated-objects
相关推荐
Now in version 4, Rails is mature and powerful, and to use it effectively you need more than a few Google searches. You'll find no substitute for the guru's-eye-view of design, testing, deployment, ...
Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...
Rails 4 Test Prescriptions.pdf
Beginning Rails 4
Rails test described by RSpec
Rails 4 in Action, Second Edition.pdf
[Pragmatic Bookshelf] Crafting Rails 4 Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Get ready to see Rails as you've never seen it before. Learn how to ...
唔,1分应该还是有人下的吧,共同学习进步,Ruby on Rails is an open source web framework.... "Rails 4 in Action" is a fully-revised second edition of "Rails 3 in Action." This hands-on, compreh...
一本Rails 4开发进阶教程,适合有一定开发经验的Ruby on Rails开发人员阅读
学习ruby!
Rails 4 Test Prescriptions is a comprehensive guide to how tests can help you design and write better Rails applications. In this completely revised edition, you'll learn why testing works and how to...
Ruby on Rails4 api.chm ruby on rails 4 最新api chm版本,方便大家阅览!
Ruby on Rails框架是Ruby的一个杀手级应用框架,可以敏捷开发Web应用,是目前为止开发效率最高的Web开发技术
Crafting Rails 4 Applications
todo-rails4-angularjs, Rails 4和AngularJS集成的展示 Rails 4和AngularJS集成的展示这是一个待办事项列表管理应用程序,用 Rails 4和AngularJS编写。 任务支持CRUD操作以及drag&拖放排序和通过弹出式日历设置的...
Book Details Publisher: Addison-Wesley Professional By: Obie Fernandez ISBN-10: 0321944275 ISBN-13: 978-0321944276 Year: June 8, 2014 Pages: 912 Language: English File size: 4 MB File format: PDF
rails4gems.part3.rar rails4常用gem3
一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码