【问题标题】:How can I get value from user custom field如何从用户自定义字段中获取价值
【发布时间】:2020-12-17 10:38:38
【问题描述】:

我有一个计算字段,我想从用户(职位、经理)之前创建的自定义字段中添加一个值

这里的例子https://i.stack.imgur.com/Bg9uX.png

我设法通过用户名传递给该字段

User.current.id

如何将这 2 个字段传递给计算 试图传递值 cfs[22] 不幸的是,它没有成功

【问题讨论】:

  • 您是想仅在 Redmine 中执行此操作,还是需要使用 API 或任何集成来执行此操作?

标签: ruby-on-rails-4 redmine custom-fields


【解决方案1】:

访问一个 id = 10 的自定义字段值,试试这个:

# Getting the current User object
u = User.current
# Accessing the value for custom field which id = 10
u.custom_field_value(10)

要为 id = 10 的自定义字段分配一个值,此代码应该可以工作:

# Getting the current User object
u = User.current
# Assigning the value 'value' to the custom field which id = 10
u.custom_field_values=({'10'=>'value'})
# Persisting the change
u.save

您可以组合这些方法,例如,将 id = 11 的自定义字段值与 id = 10 的自定义字段值分配:

u.custom_field_values=({'11'=>u.custom_field_value(10)})
# Remember to persist the change
u.save

rails c 可以方便您探索 Object 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    相关资源
    最近更新 更多