igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner
https://www.railsjazz.com/
MIT License
1.46k stars 111 forks source link

Unsupported field types #39

Closed bbenezech closed 8 years ago

bbenezech commented 8 years ago

Hello again,

Simple form doesn't support all field types. For example jsonb columns will raise

ActionView::Template::Error (No input found for jsonb):
    14:           </div>
    15:
    16:         <% else %>
    17:           <%= form.input name, label: name %>
    18:         <% end %>
    19:       <% end %>
    20:     </div>
  simple_form (3.2.0) lib/simple_form/form_builder.rb:574:in `find_mapping'
  simple_form (3.2.0) lib/simple_form/form_builder.rb:503:in `find_input'
  simple_form (3.2.0) lib/simple_form/form_builder.rb:113:in `input'
  rails_db (1.0) app/views/rails_db/tables/_edit.html.erb:17:in `block (2 levels) in ___sers_ben__rvm_gems_ruby_______gems_rails_db_____app_views_rails_db_tables__edit_html_erb___3087035280528385302_70164055306820'

The way you handle it is your call. I guess I would default to text. Not sure how.

Catching around form.input name, label: name and retrying with as: :text looks dirty, maybe you can try to toy around SimpleForm API to see if they expose smtg than can help you in find_mapping.

Unless you want to go with user-faced config hooks, but I sure wouldn't!

igorkasyanchuk commented 8 years ago

@bbenezech please add me in skype - "igorkasyanchuk" if you want. I really like what you are making and found issues you have found and your solutions. I think we can discuss them and plan fixes together if you want.

bbenezech commented 8 years ago

SimpleForm fallbacks on custom types named after field's type.

For ex. a jsonb field would need an app/inputs/jsonb_input.rb file:

class JsonbInput < SimpleForm::Inputs::TextInput; end

It works fine with a limited hassle.