2017-06-18 94 views
0

在带有postgres的Rails 4.2应用程序中,字段ui_layout在db表(psql支持json数据类型)中转换为jsonui_layout曾经是text字段。在db表转换ui_layoutjson后,输入表格new的呈现返回错误如下:Rails 4.2:带有json字段的输入表单的错误

ActionView::Template::Error (No input found for json): 
    48:       <%= f.input :footer, :label => ('Footer') %> 
    49:       <%= f.input :time_periods, :label => ('Time Periods') %> 
    50:       <%= f.input :max_time_period, :label => ('max Time Period') %> 
    51:       <%= f.input :ui_layout, :label => ('UI Layout (json)'), :input_html => {:rows => 2} %> 
    52: 
    53: 
    54:       <div class="btn-toolbar" > 
    simple_form (3.1.1) lib/simple_form/form_builder.rb:574:in `find_mapping' 
    simple_form (3.1.1) lib/simple_form/form_builder.rb:503:in `find_input' 
    simple_form (3.1.1) lib/simple_form/form_builder.rb:113:in `input' 
    /home/ubuntu/.rvm/gems/ruby-2.1.2/bundler/gems/onboard_data_uploadx-f2c20c94f7d6/app/views/onboard_data_uploadx/dashboard_details/_form_new.html.erb:51:in `block in __home_ubuntu__rvm_gems_ruby_______bundler_gems_onboard_data_uploadx_f_c__c__f_d__app_views_onboard_data_uploadx_dashboard_details__form_new_html_erb__2939072899287253628_79696400' 
    actionview (4.2.0) lib/action_view/helpers/capture_helper.rb:38:in `block in capture' 
    actionview (4.2.0) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer' 

new输入形式中,ui_layout作为text场处理。什么是进入json字段的正确方法?我是否需要输入文本并将其转换为控制器中的json?非常感谢。

回答

1

::的ActionView ::模板错误(没有输入发现JSON)

通过本身,simple_form不支持JSON数据类型。不过你可以用覆盖输入类型这应该可以解决问题

<%= f.input :ui_layout, as: :text, :label => ('UI Layout (json)'), :input_html => {:rows => 2} %>