以下是2个模型(Rails 4.2)customer
和address
。 customer
has_one
address
。
class Customer < ActiveRecord::Base
has_one :address, autosave: true, dependent: :destroy
end
class Address < ActiveRecord::Base
belongs_to :customer
validates :add_line, :presence => true
end
将autosave
设置为true后,address
会与customer
一起保存。但是,如果address
无效,那么我们根本不想保存customer
。我们的问题是如何设置has_one
关联,以便在customer
无效时自动发生address
的回滚?
答案 0 :(得分:1)
在保存客户之前使用List<WebElement> buttons = driver.findElements(By.xpath("your xpath"));
WebElement secondButton = buttons.get(1);
验证地址。
validates_associated