0
class Subscription < ActiveRecord::Base
validates :feed_id, presence: true, uniqueness: true
現在,我驗證用戶不能預訂同一飼料兩次按上面的代碼,我想在一個通知,他們已經訂閱了指定飼料。我怎麼可以去指定的條件,如果驗證失敗,發送通知,比一般的其他「訂閱不成功」的Rails:指定基於失敗的ActiveRecord的自定義操作保存
class SubscriptionsController < ApplicationController
def new
#do things
if @subscription.save
redirect_to reader_url, notice: "You are now subscribed to: "+feed.title
else
redirect_to reader_url, notice: "Subscribe was unsuccessful!"
end
end
看起來像這是正確的,我只需要弄清楚如何在.errors枚舉上執行條件 –