簡體   English   中英

如何並排使用simple_form和formtastic(active_admin)?

[英]How to use simple_form and formtastic (active_admin) side by side?

我有一個rails項目,它使用active_admin gem。 這個active_admin取決於formtastic gem。 但是,我想在我的應用程序中使用simple_form而不是formtastic(在active_admin之外的所有部分中)。

問題:simple_form和formtastic都聲明了“simple_form_for”幫助器,並且通常具有非常相似的DSL。

如何在我的應用程序中使用simple_form,同時仍保持active_admin(及其formtastic)?

如果你問自己,為什么我需要這樣一個麻煩的設置:我使用twitter bootstrap和simple_form很好地支持bootstrap,而formtastic不支持。

我認為現在(2015+) ,確保SimpleFormFormtastic兼容的最簡單和最正確的方法(包括ActiveAdmin依賴)是將自定義SimpleForm輸入包裝在命名空間中

# If needed, you can namespace your custom inputs in a module and tell `SimpleForm`
# to look for their definitions in this module. This can avoid conflicts with other
# form libraries (like `Formtastic`) that look up the global context to find inputs
# definition too.

# app/inputs/custom_inputs/numeric_input.rb
module CustomInputs
  class NumericInput < SimpleForm::Inputs::NumericInput
    def input_html_classes
      super.push 'no-spinner'
    end
  end
end


# config/initializers/simple_form.rb
config.custom_inputs_namespaces << 'CustomInputs'

有關詳細信息,請查看SimpleForm 文檔的“ 自定義輸入”部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM