摘要: delete() 和destroy() 这两组类方法有什么区别呢? delete() 方法绕过了ActiveRecord 的回调和验证,而destroy()方法则可以确保调用这些功能。一般而言,最好是使用destroy()方法,因为这样可以确保进行模型类中定义的业务规则检查,以保证数据库的完整性。has_many has_one belongs_to都有设置dependent属性has_many的文档里写的dependent是设置为:destroy将调用关联对象destroy方法,如果设置为:delete_all将调用class.delete_all而不调用destroy方法,:nulli.. 阅读全文
posted @ 2012-12-04 17:09 进化论 阅读(239) 评论(0) 推荐(0) 编辑
摘要: <% for post in @posts %> <tr> <td><%= link_to 'Show', post %></td> <td><%= link_to 'Edit', edit_post_path(post) %></td> <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %> 阅读全文
posted @ 2012-12-04 15:39 进化论 阅读(160) 评论(0) 推荐(0) 编辑