Question

active_scaffold :formats do |config|
    format_order = Format.find(:all, :select => :format_order, :order => :format_order).collect(&:format_order)
    format_order << format_order.size + 1  # I want only implement when new
    config.columns = [:name, :format_order]
    config.columns[:format_order].form_ui = :select
    config.columns[:format_order].options = {
      :options => format_order
    }
    config.list.columns = [:name, :format_order]
  end

Je veux si je nouveau format, format_order ajoutera un numéro code (format_order.size + 1), mais je ne veux pas le mettre en œuvre pour modifier. Aidez-moi, s'il vous plaît. merci

Était-ce utile?

La solution

Vous devrez mettre en œuvre un rappel:

class Format < ActiveRecord::Base
...
  after_validation(:on => :create) do
    self.code = whatever_code_you_want_to_assign #
  end
...
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top