Formattastic,符号预修改

发布于 2024-09-04 14:32:45 字数 193 浏览 4 评论 0原文

我在 Formtastic 表单上输入/选择

f.input :some_model_values, :as => :select

问题是我需要预先定义:some_model_values。因为某些用户角色必须查看所有列表,而另一些则不能。

怎样才能做到呢?

谢谢。

I have input/select on Formtastic form

f.input :some_model_values, :as => :select

The problem is i need to pre define :some_model_values. Because some users roles have to see all list, and some others not.

How it can be done?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殤城〤 2024-09-11 14:32:45

在你看来:

f.input :property, :as => :select, :collection => get_property_collection(@user)

在你的助手中:

def get_property_collection(user)
  case
    when user.is_admin?
      [ "foo", "bar" ]
    else
      [ "some", "thing" ]
  end
end

in your view:

f.input :property, :as => :select, :collection => get_property_collection(@user)

in your helper:

def get_property_collection(user)
  case
    when user.is_admin?
      [ "foo", "bar" ]
    else
      [ "some", "thing" ]
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文