Skip to content
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

Extend column_for_attribute to work with form helpers (simple_form, etc) #26

Open
peck opened this issue May 5, 2014 · 6 comments
Open

Comments

@peck
Copy link

peck commented May 5, 2014

Any interest in adding this to the gem itself? I find myself using using the following function in my models that I pass into simple_form builders to have the fields show up as the correct type, and not just default to text after receiving nil.

    def column_for_attribute(attr)
     atr = hstore_metadata_for_properties[attr]
     if attr
       OpenStruct.new(type: atr)
     else
       super(attr)
     end
    end
@peck peck changed the title Extend column_for_attribute to work with form helpers (simple_form, etc)? Extend column_for_attribute to work with form helpers (simple_form, etc) May 5, 2014
@jhirn
Copy link
Contributor

jhirn commented May 5, 2014

This seems useful. Can you create a PR with some tests?

@peck
Copy link
Author

peck commented May 5, 2014

Will do, have to work through some things downstream in the process for updating attributes and making sure all is good there, but yes, Ill put it on my to-do list and see what I can come up with.

@thegrubbsian
Copy link
Member

Shouldn't use OpenStruct here, just create a regular Struct somewhere to avoid method cache busting every time an hstore class is used in a form build.

@jhirn
Copy link
Contributor

jhirn commented May 5, 2014

+1 for no OpenStruct. In fact, it should respect the original return type of column_for_attribute as closely as possible. While Struct/OpenStruct might meet the needs of simple_form, it could be surprising to someone expecting a different object.

@crismali
Copy link
Contributor

@peck, are you still hacking on this?

@crismali
Copy link
Contributor

This c1c16fb is a start on this.

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

No branches or pull requests

4 participants