New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

active admin doesn't work with simple form #2703

Closed
alexandrz opened this Issue Nov 15, 2013 · 36 comments

Comments

Projects
None yet
@alexandrz

alexandrz commented Nov 15, 2013

wrong number of arguments (6 for 4..5)
Extracted source (around line #1):
1

  insert_tag renderer_for(:new)

simple_form (3.0.0) lib/simple_form/inputs/base.rb:50:in `initialize'
formtastic (2.3.0.rc2) lib/formtastic/helpers/input_helper.rb:241:in `new'
formtastic (2.3.0.rc2) lib/formtastic/helpers/input_helper.rb:241:in `input'
/Users/sashazykov/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-7ad6ec39d959/lib/active_admin/form_builder.rb:26:in `block in input'
/Users/sashazykov/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-7ad6ec39d959/lib/active_admin/form_builder.rb:134:in `with_new_form_buffer'
/Users/sashazykov/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-7ad6ec39d959/lib/active_admin/form_builder.rb:26:in `input'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:329:in `block in fieldset_contents_from_column_list'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:317:in `collect'`
@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Nov 18, 2013

Member

Simply adding the simple_form gem to my Rails app wasn't enough to get an error; can you provide steps to reproduce this?

Member

seanlinsley commented Nov 18, 2013

Simply adding the simple_form gem to my Rails app wasn't enough to get an error; can you provide steps to reproduce this?

@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Nov 19, 2013

Member

I'm pruning inactive issues right now, so I'm going to close this ticket. Please feel free to post more information if you're still experiencing this.

Member

seanlinsley commented Nov 19, 2013

I'm pruning inactive issues right now, so I'm going to close this ticket. Please feel free to post more information if you're still experiencing this.

@tgautier

This comment has been minimized.

Show comment
Hide comment
@tgautier

tgautier Nov 20, 2013

Contributor

I'm having the same issue using the following gems:

gem 'rails',                '4.0.1'

gem 'activeadmin',          github: 'gregbell/active_admin'
gem 'simple_form',          '~> 3.0.0'

@seanlinsley just adding the simple_form gem does not cause the issue, you need to have its initializer too.

Contributor

tgautier commented Nov 20, 2013

I'm having the same issue using the following gems:

gem 'rails',                '4.0.1'

gem 'activeadmin',          github: 'gregbell/active_admin'
gem 'simple_form',          '~> 3.0.0'

@seanlinsley just adding the simple_form gem does not cause the issue, you need to have its initializer too.

@alexandrz

This comment has been minimized.

Show comment
Hide comment
@alexandrz

alexandrz Nov 20, 2013

Sorry, it was a new project and I had to move to formtastic, so I can't reproduce the error now.

alexandrz commented Nov 20, 2013

Sorry, it was a new project and I had to move to formtastic, so I can't reproduce the error now.

@seanlinsley seanlinsley reopened this Nov 20, 2013

@tgautier

This comment has been minimized.

Show comment
Hide comment
@tgautier

tgautier Nov 20, 2013

Contributor

If you need any more details or anything please let me know. I'd be happy to contribute in any way.

Contributor

tgautier commented Nov 20, 2013

If you need any more details or anything please let me know. I'd be happy to contribute in any way.

@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Nov 20, 2013

Member

I ran the simple_form generator this time, and tried reproducing this in both Rails 3.2.15 and 4.0.1, but couldn't get any error to occur. @tgautier could you provide reproduction steps, or could you upload a Rails app to GitHub that has this problem?

Member

seanlinsley commented Nov 20, 2013

I ran the simple_form generator this time, and tried reproducing this in both Rails 3.2.15 and 4.0.1, but couldn't get any error to occur. @tgautier could you provide reproduction steps, or could you upload a Rails app to GitHub that has this problem?

@tgautier

This comment has been minimized.

Show comment
Hide comment
@tgautier

tgautier Nov 21, 2013

Contributor

Here's a gist https://gist.github.com/tgautier/227dc5fe65427ff9f5ef with the error log I get with the above Gemfile and my two simple_form initializers.

Without the initializers active_admin is working as expected.

I don't know if this is related but I was already using devise with a User model before I tried to add active_admin. I've just ran the active_admin generator with the default AdminUer.

Contributor

tgautier commented Nov 21, 2013

Here's a gist https://gist.github.com/tgautier/227dc5fe65427ff9f5ef with the error log I get with the above Gemfile and my two simple_form initializers.

Without the initializers active_admin is working as expected.

I don't know if this is related but I was already using devise with a User model before I tried to add active_admin. I've just ran the active_admin generator with the default AdminUer.

@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Nov 21, 2013

Member

Oh, the problem is pretty obvious:

inputs = %w[
  CollectionSelectInput
  DateTimeInput
  FileInput
  GroupedCollectionSelectInput
  NumericInput
  PasswordInput
  RangeInput
  StringInput
  TextInput
]

inputs.each do |input_type|
  superclass = "SimpleForm::Inputs::#{input_type}".constantize

  new_class = Class.new(superclass) do
    def input_html_classes
      super.push('form-control')
    end
  end

  Object.const_set(input_type, new_class)
end

Formtastic looks up your custom input classes in the root namespace, just like it appears that simple_form does from your code above.

Member

seanlinsley commented Nov 21, 2013

Oh, the problem is pretty obvious:

inputs = %w[
  CollectionSelectInput
  DateTimeInput
  FileInput
  GroupedCollectionSelectInput
  NumericInput
  PasswordInput
  RangeInput
  StringInput
  TextInput
]

inputs.each do |input_type|
  superclass = "SimpleForm::Inputs::#{input_type}".constantize

  new_class = Class.new(superclass) do
    def input_html_classes
      super.push('form-control')
    end
  end

  Object.const_set(input_type, new_class)
end

Formtastic looks up your custom input classes in the root namespace, just like it appears that simple_form does from your code above.

@tgautier

This comment has been minimized.

Show comment
Hide comment
@tgautier

tgautier Nov 21, 2013

Contributor

I feel quite dumb, I didn't really know about formstatic insides.

I've refactored this part and it works. Thanks !

Contributor

tgautier commented Nov 21, 2013

I feel quite dumb, I didn't really know about formstatic insides.

I've refactored this part and it works. Thanks !

@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Nov 21, 2013

Member

Awesome :)

For others that come across this problem later on, how exactly did you solve this?

Member

seanlinsley commented Nov 21, 2013

Awesome :)

For others that come across this problem later on, how exactly did you solve this?

@nyashkn

This comment has been minimized.

Show comment
Hide comment
@nyashkn

nyashkn Dec 2, 2013

Facing this problem. @tgautier Kindly update your gist.

nyashkn commented Dec 2, 2013

Facing this problem. @tgautier Kindly update your gist.

@tgautier

This comment has been minimized.

Show comment
Hide comment
@tgautier

tgautier Dec 2, 2013

Contributor

Sorry for the delay, I've just removed the explicit inputs to only use simple_form's wrappers.

See the gist for the correct wrapper that works with bootstrap 3: https://gist.github.com/tgautier/c4912f2ac9b9f72c610a

Don't know if it helps.

Contributor

tgautier commented Dec 2, 2013

Sorry for the delay, I've just removed the explicit inputs to only use simple_form's wrappers.

See the gist for the correct wrapper that works with bootstrap 3: https://gist.github.com/tgautier/c4912f2ac9b9f72c610a

Don't know if it helps.

@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 20, 2013

I have tried @tgautier new gist but the simple_forms loses the Bootstrap 3 look.
Maybe it is because @tgautier is using Rails 4.x and I'm using 3.x.
As far I understood Simple Form is dealing better with Rails 4.x + Bootstrap 3 than Rails 3.x.

As I don't have much time to deal with this right now, I will probably try to use rails_admin first.
If someone has any suggestion, please, let me know.

claudiosw commented Dec 20, 2013

I have tried @tgautier new gist but the simple_forms loses the Bootstrap 3 look.
Maybe it is because @tgautier is using Rails 4.x and I'm using 3.x.
As far I understood Simple Form is dealing better with Rails 4.x + Bootstrap 3 than Rails 3.x.

As I don't have much time to deal with this right now, I will probably try to use rails_admin first.
If someone has any suggestion, please, let me know.

@ccaputo

This comment has been minimized.

Show comment
Hide comment
@ccaputo

ccaputo Dec 23, 2013

If always using simple_form with Bootstrap 3, you can do:

SimpleForm.setup do |config|
  config.input_class = 'form-control'
end

instead of the superclass method which conflicts with Formtastic.

(correction welcome)

ccaputo commented Dec 23, 2013

If always using simple_form with Bootstrap 3, you can do:

SimpleForm.setup do |config|
  config.input_class = 'form-control'
end

instead of the superclass method which conflicts with Formtastic.

(correction welcome)

@Lordnibbler

This comment has been minimized.

Show comment
Hide comment
@Lordnibbler

Lordnibbler Dec 28, 2013

@ccaputo your suggestion worked for me with this issue (added to simple_form.rb), I was able to remove the initializer that @seanlinsley pointed out.

Lordnibbler commented Dec 28, 2013

@ccaputo your suggestion worked for me with this issue (added to simple_form.rb), I was able to remove the initializer that @seanlinsley pointed out.

@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 30, 2013

@ccaputo, sorry for the delay and thanks for the reply.
I tested it today and unfortunately this haven't worked for me :(

claudiosw commented Dec 30, 2013

@ccaputo, sorry for the delay and thanks for the reply.
I tested it today and unfortunately this haven't worked for me :(

@Lordnibbler

This comment has been minimized.

Show comment
Hide comment
@Lordnibbler

Lordnibbler Dec 30, 2013

@claudiosw what does not work, please be more specific so we can try to help

Lordnibbler commented Dec 30, 2013

@claudiosw what does not work, please be more specific so we can try to help

@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 31, 2013

@Lordnibbler, sorry...
I haven't done a complete investigation what is not working but the at least the text input fields loses the Bootstrap 3 look when I remove the code the @seanlinsley pointed out and include @ccaputo's

claudiosw commented Dec 31, 2013

@Lordnibbler, sorry...
I haven't done a complete investigation what is not working but the at least the text input fields loses the Bootstrap 3 look when I remove the code the @seanlinsley pointed out and include @ccaputo's

@ccaputo

This comment has been minimized.

Show comment
Hide comment
@ccaputo

ccaputo Dec 31, 2013

@claudiosw I use the following. These can probably be consolidated in to a single file, but I haven't taken the time to do so.

config/initializers/simple_form.rb:

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  # Wrappers are used by the form builder to generate a
  # complete input. You can remove any component from the
  # wrapper, change the order or even add your own to the
  # stack. The options given below are used to wrap the
  # whole input.
  config.wrappers :default, class: :input,
    hint_class: :field_with_hint, error_class: :field_with_errors do |b|
    ## Extensions enabled by default
    # Any of these extensions can be disabled for a
    # given input by passing: `f.input EXTENSION_NAME => false`.
    # You can make any of these extensions optional by
    # renaming `b.use` to `b.optional`.

    # Determines whether to use HTML5 (:email, :url, ...)
    # and required attributes
    b.use :html5

    # Calculates placeholders automatically from I18n
    # You can also pass a string as f.input placeholder: "Placeholder"
    b.use :placeholder

    ## Optional extensions
    # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
    # to the input. If so, they will retrieve the values from the model
    # if any exists. If you want to enable the lookup for any of those
    # extensions by default, you can change `b.optional` to `b.use`.

    # Calculates maxlength from length validations for string inputs
    b.optional :maxlength

    # Calculates pattern from format validations for string inputs
    b.optional :pattern

    # Calculates min and max from length validations for numeric inputs
    b.optional :min_max

    # Calculates readonly automatically from readonly attributes
    b.optional :readonly

    ## Inputs
    b.use :label_input
    b.use :hint,  wrap_with: { tag: :span, class: :hint }
    b.use :error, wrap_with: { tag: :span, class: :error }
  end

  # The default wrapper to be used by the FormBuilder.
  config.default_wrapper = :default

  # Define the way to render check boxes / radio buttons with labels.
  # Defaults to :nested for bootstrap config.
  #   inline: input + label
  #   nested: label > input
  config.boolean_style = :nested

  # Default class for buttons
  config.button_class = 'btn btn-default'

  # Method used to tidy up errors. Specify any Rails Array method.
  # :first lists the first message for each field.
  # Use :to_sentence to list all errors for each field.
  # config.error_method = :first

  # Default tag used for error notification helper.
  config.error_notification_tag = :div

  # CSS class to add for error notification helper.
  config.error_notification_class = 'alert alert-danger'

  # ID to add for error notification helper.
  # config.error_notification_id = nil

  # Series of attempts to detect a default label method for collection.
  # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]

  # Series of attempts to detect a default value method for collection.
  # config.collection_value_methods = [ :id, :to_s ]

  # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
  # config.collection_wrapper_tag = nil

  # You can define the class to use on all collection wrappers. Defaulting to none.
  # config.collection_wrapper_class = nil

  # You can wrap each item in a collection of radio/check boxes with a tag,
  # defaulting to :span. Please note that when using :boolean_style = :nested,
  # SimpleForm will force this option to be a label.
  # config.item_wrapper_tag = :span

  # You can define a class to use in all item wrappers. Defaulting to none.
  # config.item_wrapper_class = nil

  # How the label text should be generated altogether with the required text.
  # config.label_text = lambda { |label, required| "#{required} #{label}" }

  # You can define the class to use on all labels. Default is nil.
  config.label_class = 'control-label'

  # You can define the class to use on all forms. Default is simple_form.
  # config.form_class = :simple_form

  # You can define which elements should obtain additional classes
  # config.generate_additional_classes_for = [:wrapper, :label, :input]

  # Whether attributes are required by default (or not). Default is true.
  # config.required_by_default = true

  # Tell browsers whether to use the native HTML5 validations (novalidate form option).
  # These validations are enabled in SimpleForm's internal config but disabled by default
  # in this configuration, which is recommended due to some quirks from different browsers.
  # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
  # change this configuration to true.
  config.browser_validations = false

  # Collection of methods to detect if a file type was given.
  # config.file_methods = [ :mounted_as, :file?, :public_filename ]

  # Custom mappings for input types. This should be a hash containing a regexp
  # to match as key, and the input type that will be used when the field name
  # matches the regexp as value.
  # config.input_mappings = { /count/ => :integer }

  # Custom wrappers for input types. This should be a hash containing an input
  # type as key and the wrapper that will be used for all inputs with specified type.
  # config.wrapper_mappings = { string: :prepend }

  # Default priority for time_zone inputs.
  # config.time_zone_priority = nil

  # Default priority for country inputs.
  # config.country_priority = nil

  # When false, do not use translations for labels.
  # config.translate_labels = true

  # Automatically discover new inputs in Rails' autoload path.
  # config.inputs_discovery = true

  # Cache SimpleForm inputs discovery
  # config.cache_discovery = !Rails.env.development?

  # Default class for inputs
  # config.input_class = nil
end

config/initializers/simple_form_bootstrap3.rb:

SimpleForm.setup do |config|
  # For Twitter Bootstrap 3 rather than redefining Inputs and conflicting with Formtastic.
  config.input_class = 'form-control'

  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end

ccaputo commented Dec 31, 2013

@claudiosw I use the following. These can probably be consolidated in to a single file, but I haven't taken the time to do so.

config/initializers/simple_form.rb:

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  # Wrappers are used by the form builder to generate a
  # complete input. You can remove any component from the
  # wrapper, change the order or even add your own to the
  # stack. The options given below are used to wrap the
  # whole input.
  config.wrappers :default, class: :input,
    hint_class: :field_with_hint, error_class: :field_with_errors do |b|
    ## Extensions enabled by default
    # Any of these extensions can be disabled for a
    # given input by passing: `f.input EXTENSION_NAME => false`.
    # You can make any of these extensions optional by
    # renaming `b.use` to `b.optional`.

    # Determines whether to use HTML5 (:email, :url, ...)
    # and required attributes
    b.use :html5

    # Calculates placeholders automatically from I18n
    # You can also pass a string as f.input placeholder: "Placeholder"
    b.use :placeholder

    ## Optional extensions
    # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
    # to the input. If so, they will retrieve the values from the model
    # if any exists. If you want to enable the lookup for any of those
    # extensions by default, you can change `b.optional` to `b.use`.

    # Calculates maxlength from length validations for string inputs
    b.optional :maxlength

    # Calculates pattern from format validations for string inputs
    b.optional :pattern

    # Calculates min and max from length validations for numeric inputs
    b.optional :min_max

    # Calculates readonly automatically from readonly attributes
    b.optional :readonly

    ## Inputs
    b.use :label_input
    b.use :hint,  wrap_with: { tag: :span, class: :hint }
    b.use :error, wrap_with: { tag: :span, class: :error }
  end

  # The default wrapper to be used by the FormBuilder.
  config.default_wrapper = :default

  # Define the way to render check boxes / radio buttons with labels.
  # Defaults to :nested for bootstrap config.
  #   inline: input + label
  #   nested: label > input
  config.boolean_style = :nested

  # Default class for buttons
  config.button_class = 'btn btn-default'

  # Method used to tidy up errors. Specify any Rails Array method.
  # :first lists the first message for each field.
  # Use :to_sentence to list all errors for each field.
  # config.error_method = :first

  # Default tag used for error notification helper.
  config.error_notification_tag = :div

  # CSS class to add for error notification helper.
  config.error_notification_class = 'alert alert-danger'

  # ID to add for error notification helper.
  # config.error_notification_id = nil

  # Series of attempts to detect a default label method for collection.
  # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]

  # Series of attempts to detect a default value method for collection.
  # config.collection_value_methods = [ :id, :to_s ]

  # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
  # config.collection_wrapper_tag = nil

  # You can define the class to use on all collection wrappers. Defaulting to none.
  # config.collection_wrapper_class = nil

  # You can wrap each item in a collection of radio/check boxes with a tag,
  # defaulting to :span. Please note that when using :boolean_style = :nested,
  # SimpleForm will force this option to be a label.
  # config.item_wrapper_tag = :span

  # You can define a class to use in all item wrappers. Defaulting to none.
  # config.item_wrapper_class = nil

  # How the label text should be generated altogether with the required text.
  # config.label_text = lambda { |label, required| "#{required} #{label}" }

  # You can define the class to use on all labels. Default is nil.
  config.label_class = 'control-label'

  # You can define the class to use on all forms. Default is simple_form.
  # config.form_class = :simple_form

  # You can define which elements should obtain additional classes
  # config.generate_additional_classes_for = [:wrapper, :label, :input]

  # Whether attributes are required by default (or not). Default is true.
  # config.required_by_default = true

  # Tell browsers whether to use the native HTML5 validations (novalidate form option).
  # These validations are enabled in SimpleForm's internal config but disabled by default
  # in this configuration, which is recommended due to some quirks from different browsers.
  # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
  # change this configuration to true.
  config.browser_validations = false

  # Collection of methods to detect if a file type was given.
  # config.file_methods = [ :mounted_as, :file?, :public_filename ]

  # Custom mappings for input types. This should be a hash containing a regexp
  # to match as key, and the input type that will be used when the field name
  # matches the regexp as value.
  # config.input_mappings = { /count/ => :integer }

  # Custom wrappers for input types. This should be a hash containing an input
  # type as key and the wrapper that will be used for all inputs with specified type.
  # config.wrapper_mappings = { string: :prepend }

  # Default priority for time_zone inputs.
  # config.time_zone_priority = nil

  # Default priority for country inputs.
  # config.country_priority = nil

  # When false, do not use translations for labels.
  # config.translate_labels = true

  # Automatically discover new inputs in Rails' autoload path.
  # config.inputs_discovery = true

  # Cache SimpleForm inputs discovery
  # config.cache_discovery = !Rails.env.development?

  # Default class for inputs
  # config.input_class = nil
end

config/initializers/simple_form_bootstrap3.rb:

SimpleForm.setup do |config|
  # For Twitter Bootstrap 3 rather than redefining Inputs and conflicting with Formtastic.
  config.input_class = 'form-control'

  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end
@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 31, 2013

@Lordnibbler, Unfortunately this isn't working for me as well.
Which Rails version are you using? I'm using the 3.x Rails version.

What about your simple_form line in the Gemfile? Mine is this:
gem 'simple_form', github: 'andrezimpel/simple_form', :branch => 'v2.1'

claudiosw commented Dec 31, 2013

@Lordnibbler, Unfortunately this isn't working for me as well.
Which Rails version are you using? I'm using the 3.x Rails version.

What about your simple_form line in the Gemfile? Mine is this:
gem 'simple_form', github: 'andrezimpel/simple_form', :branch => 'v2.1'

@seanlinsley

This comment has been minimized.

Show comment
Hide comment
@seanlinsley

seanlinsley Dec 31, 2013

Member

What do you mean by Rails 3.x? There's a world of difference between 3.0 and 3.2.

Member

seanlinsley commented Dec 31, 2013

What do you mean by Rails 3.x? There's a world of difference between 3.0 and 3.2.

@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 31, 2013

I'm using the latest 3.x. I just said because I suppose that the solution may work only with Rails 4.x

claudiosw commented Dec 31, 2013

I'm using the latest 3.x. I just said because I suppose that the solution may work only with Rails 4.x

@ccaputo

This comment has been minimized.

Show comment
Hide comment
@ccaputo

ccaputo Dec 31, 2013

@claudiosw I'm running 4.0.2. Relevant in my Gemfile:

gem 'rails', '4.0.2'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'bootstrap-sass', '~> 3.0.3.0'
gem 'simple_form', '>= 3.0.0.rc'

ccaputo commented Dec 31, 2013

@claudiosw I'm running 4.0.2. Relevant in my Gemfile:

gem 'rails', '4.0.2'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'bootstrap-sass', '~> 3.0.3.0'
gem 'simple_form', '>= 3.0.0.rc'

@claudiosw

This comment has been minimized.

Show comment
Hide comment
@claudiosw

claudiosw Dec 31, 2013

Ok. Thanks!

claudiosw commented Dec 31, 2013

Ok. Thanks!

@joshuaswilcox

This comment has been minimized.

Show comment
Hide comment
@joshuaswilcox

joshuaswilcox Jan 4, 2014

@ccaputo Adding the config.input_class now causes the server not to start with this error

simple_form.rb:4:in block in <top (required)>': undefined methodinput_class=' for SimpleForm:Module (NoMethodError)

joshuaswilcox commented Jan 4, 2014

@ccaputo Adding the config.input_class now causes the server not to start with this error

simple_form.rb:4:in block in <top (required)>': undefined methodinput_class=' for SimpleForm:Module (NoMethodError)

@ccaputo

This comment has been minimized.

Show comment
Hide comment
@ccaputo

ccaputo Jan 4, 2014

@joshuaswilcox what's your whole file look like?

ccaputo commented Jan 4, 2014

@joshuaswilcox what's your whole file look like?

@joshuaswilcox

This comment has been minimized.

Show comment
Hide comment
@joshuaswilcox

joshuaswilcox Jan 4, 2014

@ccaputo

SimpleForm.setup do |config|

  config.input_class = 'form-control'

  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Default class for buttons
  config.button_class = 'btn btn-default'

  # You can define the class to use on all labels. Default is nil.
  config.label_class = 'control-label'

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end

joshuaswilcox commented Jan 4, 2014

@ccaputo

SimpleForm.setup do |config|

  config.input_class = 'form-control'

  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Default class for buttons
  config.button_class = 'btn btn-default'

  # You can define the class to use on all labels. Default is nil.
  config.label_class = 'control-label'

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end
@ccaputo

This comment has been minimized.

Show comment
Hide comment
@ccaputo

ccaputo Jan 4, 2014

@joshuaswilcox What do you have for simple_form in your Gemfile and Gemfile.lock? If you try the two files I posted above, any better?

ccaputo commented Jan 4, 2014

@joshuaswilcox What do you have for simple_form in your Gemfile and Gemfile.lock? If you try the two files I posted above, any better?

@joshuaswilcox

This comment has been minimized.

Show comment
Hide comment
@joshuaswilcox

joshuaswilcox Jan 9, 2014

@ccaputo I am on rails 3, I think that might be the issue, this bug was for rails 4, i'll just stick to adding the class to the forms

joshuaswilcox commented Jan 9, 2014

@ccaputo I am on rails 3, I think that might be the issue, this bug was for rails 4, i'll just stick to adding the class to the forms

@rylanb

This comment has been minimized.

Show comment
Hide comment
@rylanb

rylanb Mar 13, 2014

http://stackoverflow.com/questions/20892727/active-admin-argumenterror-in-sessionsnew-rails-4-1-0-beta1 might answer the question for some people on rails 4.1RC as it did for me.

Gemfile: gem "formtastic", github: "justinfrench/formtastic" was the relevant part to get formtastic master.

rylanb commented Mar 13, 2014

http://stackoverflow.com/questions/20892727/active-admin-argumenterror-in-sessionsnew-rails-4-1-0-beta1 might answer the question for some people on rails 4.1RC as it did for me.

Gemfile: gem "formtastic", github: "justinfrench/formtastic" was the relevant part to get formtastic master.

@SpecialCyCi

This comment has been minimized.

Show comment
Hide comment
@SpecialCyCi

SpecialCyCi Mar 20, 2014

@claudiosw I tried to modify the code in https://gist.github.com/tokenvolt/6599141, the following code works for me now.
Rails 3.2.16 + active_admin + simple_form 2.1.1

inputs = %w[
  CollectionSelectInput
  DateTimeInput
  FileInput
  GroupedCollectionSelectInput
  NumericInput
  PasswordInput
  RangeInput
  StringInput
  TextInput
]

inputs.each do |input_type|
  superclass = "SimpleForm::Inputs::#{input_type}"
  hack = %|
    module SimpleForm
      module Inputs
        class #{superclass}
          def input_html_classes
            super.push('form-control')
          end
        end
      end
    end
  |
  eval(hack)

end

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end

SpecialCyCi commented Mar 20, 2014

@claudiosw I tried to modify the code in https://gist.github.com/tokenvolt/6599141, the following code works for me now.
Rails 3.2.16 + active_admin + simple_form 2.1.1

inputs = %w[
  CollectionSelectInput
  DateTimeInput
  FileInput
  GroupedCollectionSelectInput
  NumericInput
  PasswordInput
  RangeInput
  StringInput
  TextInput
]

inputs.each do |input_type|
  superclass = "SimpleForm::Inputs::#{input_type}"
  hack = %|
    module SimpleForm
      module Inputs
        class #{superclass}
          def input_html_classes
            super.push('form-control')
          end
        end
      end
    end
  |
  eval(hack)

end

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  config.boolean_style = :nested

  config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label_input
    b.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end

  config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
        prepend.use :input
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper tag: 'div', class: 'controls' do |input|
      input.wrapper tag: 'div', class: 'input-group' do |prepend|
        prepend.use :input
    prepend.use :label , class: 'input-group-addon' ###Please note setting class here fro the label does not currently work (let me know if you know a workaround as this is the final hurdle)
      end
      input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
      input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
    end
  end

  config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5

    # Form components
    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://getbootstrap.com/)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap3
end
@baxang

This comment has been minimized.

Show comment
Hide comment
@baxang

baxang Mar 21, 2014

@SpecialCyCi Thanks for the code. It worked well for me on AA master with Rails 4.0.3.

baxang commented Mar 21, 2014

@SpecialCyCi Thanks for the code. It worked well for me on AA master with Rails 4.0.3.

@padde

This comment has been minimized.

Show comment
Hide comment
@padde

padde May 27, 2014

Your solutions seems unnecessarily complex, @SpecialCyCi. It makes use of eval, which should not be required. This fixes the issue for me as well and is much simpler:

# [incorrect code removed by author to prevent accidental copy & paste]

padde commented May 27, 2014

Your solutions seems unnecessarily complex, @SpecialCyCi. It makes use of eval, which should not be required. This fixes the issue for me as well and is much simpler:

# [incorrect code removed by author to prevent accidental copy & paste]
@SpecialCyCi

This comment has been minimized.

Show comment
Hide comment
@SpecialCyCi

SpecialCyCi commented May 27, 2014

@padde awesome! 👍

@padde

This comment has been minimized.

Show comment
Hide comment
@padde

padde May 27, 2014

@SpecialCyCi there is actually an issue with my previous solution, because it overwrites the existing input_html_classes method instead of adding to it. While I don't know whether this would be a problem in practice, the better way to do it is this:

inputs.each do |input_type|
  "SimpleForm::Inputs::#{input_type}".constantize.class_eval do
    alias_method :__input_html_classes, :input_html_classes
    define_method(:input_html_classes) do
      __input_html_classes.push('form-control')
    end
  end
end

padde commented May 27, 2014

@SpecialCyCi there is actually an issue with my previous solution, because it overwrites the existing input_html_classes method instead of adding to it. While I don't know whether this would be a problem in practice, the better way to do it is this:

inputs.each do |input_type|
  "SimpleForm::Inputs::#{input_type}".constantize.class_eval do
    alias_method :__input_html_classes, :input_html_classes
    define_method(:input_html_classes) do
      __input_html_classes.push('form-control')
    end
  end
end
@jibiel

This comment has been minimized.

Show comment
Hide comment
@jibiel

jibiel Sep 29, 2015

I think that nowadays (2015+), the simplest and the most proper way to ensure SimpleForm's compatibility with Formtastic (including the ActiveAdmin dependency) is to wrap your custom SimpleForm inputs in a namespace:

# 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'

Check the Custom Inputs section of the SimpleForm docs for more details.

jibiel commented Sep 29, 2015

I think that nowadays (2015+), the simplest and the most proper way to ensure SimpleForm's compatibility with Formtastic (including the ActiveAdmin dependency) is to wrap your custom SimpleForm inputs in a namespace:

# 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'

Check the Custom Inputs section of the SimpleForm docs for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment