-
options_for_select limit the type of first permittedAttribute args must same as the second list args value. e.g. class University < BaseModel
enum BatchLevel
LevelOne_A
LevelOne_B
LevelTwo_A
LevelTwo_B
def to_s
case self
in LevelOne_A
"一本A"
in LevelOne_B
"一本B"
in LevelTwo_A
"二本A"
in LevelTwo_B
"二本B"
end
end
def self.checkbox_batch_level
values = [] of Tuple(String, Int32)
BatchNumber.each { |bn| values << {bn.to_s, bn.value} }
values
end
end
table do
column batch_level : University::BatchLevel
end
end In the page
This will get error like this: Error: no overload matches 'Universities::FormFields#options_for_select' with types AFAIK, there is two solution:
I consider both of them not good, is there a better way to do this? thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seem like works change code like this: class University < BaseModel
enum BatchLevel
LevelOne_A
LevelOne_B
LevelTwo_A
LevelTwo_B
def display_name
case self
in LevelOne_A
"一本A"
in LevelOne_B
"一本B"
in LevelTwo_A
"二本A"
in LevelTwo_B
"二本B"
end
end
def self.checkbox_batch_level
values = [] of Tuple(String, University::BatchLevel)
BatchNumber.each { |bn| values << {bn.display_name, bn} }
values
end
end
table do
column batch_level : University::BatchLevel
end
end Then use in page like this: options_for_select(op.batch_level, University::BatchNumber.checkbox_batch_level) |
Beta Was this translation helpful? Give feedback.
It seem like works change code like this:
Then use in page like this: