Rails方法评估用户输入(Rails method evaluating user input)
我试图在用户提交表单时检查特定条目组合“entry_conditions”。
如果用户为entry_conditions(a或b)中的任何一个输入了这些确切的值,我会想要“meets_any_entry_conditions?”为true。 但我正在努力与结构。
def entry_conditions condition a = [fielda: 6, fieldb: 6, fieldc: 6] condition b = [fielde: 10, fieldf: 10, fieldg: 10] end def meets_any_entry_conditions? entry_conditions.any? endI’m trying to check for specific entry condition combinations “entry_conditions” when a user submits a form.
If the user enters these exact values for either of the entry_conditions (a or b), I would like “meets_any_entry_conditions?” to be true. But I’m struggling with the structure.
def entry_conditions condition a = [fielda: 6, fieldb: 6, fieldc: 6] condition b = [fielde: 10, fieldf: 10, fieldg: 10] end def meets_any_entry_conditions? entry_conditions.any? end最满意答案
def entry_conditions [{fielda: 6, fieldb: 6, fieldc: 6},{fielde: 10, fieldf: 10, fieldg: 10}] end def meets_any_entry_conditions? entry_conditions.each do |condition| passed = true condition.each do |k, v| passed = false unless send(k) == v break unless passed end return true if passed end false end def entry_conditions [{fielda: 6, fieldb: 6, fieldc: 6},{fielde: 10, fieldf: 10, fieldg: 10}] end def meets_any_entry_conditions? entry_conditions.each do |condition| passed = true condition.each do |k, v| passed = false unless send(k) == v break unless passed end return true if passed end false end更多推荐
发布评论