ruby 如何检查模板中的录入权限

rur96b6h  于 2023-03-08  发布在  Ruby
关注(0)|答案(2)|浏览(134)

我可以访问输入值并检查它的值吗?我想禁用改变键的能力,如果它等于'foo'。

.email-template-param-nested-fields
  - if :key == 'foo'
    = f.input :key, placeholder: 'foo', readonly: true
  - else
    = f.input :key, placeholder: 'key'
  = f.input :value, placeholder: 'example'
rkue9o1l

rkue9o1l1#

您可以将变量赋值为

- args = f.object.key == 'foo' ? { placeholder: 'foo', readonly: true } : { placeholder: 'key' }

然后

= f.input :key, **args
p5cysglq

p5cysglq2#

您可以执行条件内联:

.email-template-param-nested-fields
  = f.input :key, placeholder: 'foo', readonly: (f.object.key == 'foo')
  = f.input :value, placeholder: 'example'

相关问题