Ответ 1
Мне нужно было установить flash[:notice]
в модели, чтобы переопределить общий "@model был успешно обновлен".
Это то, что я сделал
- Создал виртуальный атрибут в соответствующей модели под названием
flash_notice
- Затем я устанавливаю виртуальный атрибут в соответствующей модели при необходимости
- Использовал after_filter, когда этот виртуальный атрибут не был пустым, чтобы переопределить флэш-память по умолчанию
Вы можете увидеть мой контроллер и модель, как я сделал это ниже:
class Reservation < ActiveRecord::Base
belongs_to :retailer
belongs_to :sharedorder
accepts_nested_attributes_for :sharedorder
accepts_nested_attributes_for :retailer
attr_accessor :validation_code, :flash_notice
validate :first_reservation, :if => :new_record_and_unvalidated
def new_record_and_unvalidated
if !self.new_record? && !self.retailer.validated?
true
else
false
end
end
def first_reservation
if self.validation_code != "test" || self.validation_code.blank?
errors.add_to_base("Validation code was incorrect")
else
self.retailer.update_attribute(:validated, true)
self.flash_notice = "Your validation as successful and you will not need to do that again"
end
end
end
class ReservationsController < ApplicationController
before_filter :authenticate_retailer!
after_filter :flash_notice, :except => :index
def flash_notice
if [email protected]_notice.blank?
flash[:notice] = @reservation.flash_notice
end
end
end