Rails方法评估用户输入(Rails method evaluating user input)

编程入门 行业动态 更新时间:2024-10-26 18:18:35
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? end

I’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

更多推荐

本文发布于:2023-04-29 07:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   用户   Rails   method   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!