class Requirement < ActiveRecord::Base belongs_to :report has_many :dictionaries, dependent: :destroy, as: :resource #搜索类型 FormType = { form_select: 1, #下拉 form_datetime: 2, #时间 form_text: 3 #输入 } # enum form_type: FormType #下拉数据来源类型 SqlType = { sql_dict: 1, #字典 sql_query: 2 #sql查询所得 } # enum sql_type: SqlType def form_type_name return "下拉" if self.form_type == FormType[:form_select] return "时间" if self.form_type == FormType[:form_datetime] return "输入" if self.form_type == FormType[:form_text] end def sql_type_name return "字典" if self.sql_type == SqlType[:sql_dict] return "sql查询所得" if self.sql_type == SqlType[:sql_query] end def self.sql_type_options [["", 0],["字典", SqlType[:sql_dict]],["sql查询所得", SqlType[:sql_query]]] end def self.form_type_options [["下拉", FormType[:form_select]],["时间", FormType[:form_datetime]],["输入", FormType[:form_text]]] end def dict_options self.dictionaries.collect{|s|[s.key, s.value]} end end