views:

21

answers:

1
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

I want if I new format, format_order will add a number as code (format_order.size + 1) but I don't want implement it for edit. please help me. thanks

+1  A: 

You will have to implement a callback:

class Format < ActiveRecord::Base
...
  after_validation(:on => :create) do
    self.code = whatever_code_you_want_to_assign #
  end
...
end
Swanand
thanks you very much
Nam Khanh