Simple_form: Type_for_attribute on multiple models in form object (active model)

Created on 9 Mar 2019  路  3Comments  路  Source: heartcombo/simple_form

Environment

Ruby 2.6.1
Rails 5.2.2
Simple Form 4.1

Current behavior

Currently, Simple_form uses type-for-attribute to map the field types. https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type

However, if you delegate the form object to two or more models, simple_form does not know how to map it. You can use

delegate :type_for_attribute, :has_attribute?, to: :car
delegate :type_for_attribute, :has_attribute?, to: :repair_center

However, the top delegate is lost when the bottom delegate is introduced. Hence, there needs to be a better way to map the type_for_attributes to the correct model.

https://stackoverflow.com/questions/55077702/delegate-type-for-attribute-has-attribute-to-two-different-models

Basically, a feature request, or if the feature is already available, please let me know.

-- EDIT
In my original request, I needed to find a way to call type_for_attribute on multiple models. I ended up writing a method that looks at the model the field is delegated to and calling type_for_attribute on that model to get simple form to see the types.

Most helpful comment

updated, I hope this is useful.

All 3 comments

@joshm1204 I would suggest not editing your issue the way you did. Even if you might consider your issue "wrong" or "useless", it's undoubtedly even more useless when you replace all the text with "REMOVED". There's always the chance someone made the same mistake you did. Just a note for the future.

Yeah, I'd suggest the same. Also, would be awesome to share why it's not an issue anymore. It could help others in the future.

Thanks :)

updated, I hope this is useful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gmrash picture gmrash  路  3Comments

gregblass picture gregblass  路  3Comments

aximuseng picture aximuseng  路  4Comments

piya23300 picture piya23300  路  5Comments

mszyndel picture mszyndel  路  5Comments