【问题标题】:Formtastic, pre-modification of symbolFormtastic,符号的预修改
【发布时间】:2010-06-03 09:55:02
【问题描述】:

我在 Formtastic 表单上有输入/选择

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

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

如何实现?

谢谢。

【问题讨论】:

    标签: ruby-on-rails formtastic


    【解决方案1】:

    在你看来:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-15
      • 2011-08-30
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      相关资源
      最近更新 更多