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

Adds JSON Input Type (using string type) #1045

Closed
wants to merge 1 commit into from

Conversation

justinstern
Copy link

No description provided.

@justinfrench
Copy link
Member

Could you provide more information about where/why you needed this, and why you think this is a good general use case for inclusion in Formtastic (rather than left as a custom input in your own app)?

@justinstern
Copy link
Author

Sure, so it came up in an app that uses a JSON type column (postgres) along with Active Admin. The missing JSON type causes Active Admin to blow up when editing the records from that table, with that "type not found" exception from formtastic. At the time I couldn't figure out how to override the Active Admin edit table to set the "as" to something else, but since then I've found examples of how to do so, so I can either set the "as" or remove that column from editing entirely. So at this point I'd be fine with the PR just being discarded, so far as my app is concerned.

@justinfrench
Copy link
Member

Would it be possible for you to replicate the exception/error and paste it here? Ideally Formtastic will work "out of the box" with any model without an as, so there's obviously some work to do here — maybe we do exactly what you've proposed here, or maybe we just map json columns to one of our existing inputs, since there's no difference in behaviour at this point.

@justinstern
Copy link
Author

hey cool, yeah mapping json to string would be a great solution I think, I just didn't see where to do that when I looked through the formtastic gem.

I've attached the top of the exception trace (a little tricky to get the whole thing out with better_errors installed, but if you need more just let me know and I'll figure it out):

window_and_formtastic__unknowninputerror_at__admin_feeds_3270_edit

Looks like the Formtastic exception is actually being thrown by ActiveAdmin, which is interesting

@dmitry
Copy link
Contributor

dmitry commented Jul 4, 2014

@justinstern from my experience with ActiveAdmin it's better to patch ActiveAdmin Inputs::*. This shouldn't be merged.

@justinfrench
Copy link
Member

Smells like this is something that should be resolved ActiveAdmin side. Closing for now, happy to re-open with new info.

@justinstern
Copy link
Author

Almost forgot, here's a little snippet showing what I used to work around this issue within ActiveAdmin:

ActiveAdmin.register User do

  # edit action
  form do |f|
    f.inputs do
      ...
      # allow editing of JSON field as string
      f.input :options, as: :string
    end
  end
end

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

Successfully merging this pull request may close these issues.

None yet

3 participants