0
class Subscription < ActiveRecord::Base
  validates :feed_id, presence: true, uniqueness: true

现在我验证了用户不能按照上述代码两次订阅相同的提要,我想在通知中指定他们已经订阅了提要。如果验证失败,我该如何指定条件,发送除通用“订阅不成功”以外的通知

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
4

1 回答 1

2

如果验证失败,它将填充@subscription.errors,您可以根据需要检查和显示消息。

于 2012-05-07T19:25:31.737 回答