Rails 3 очень длинная, очень медленная форма - PullRequest
1 голос
/ 17 июня 2011

У меня очень длинная форма с вложенными полями формы.Загрузка занимает 30 секунд.

Я использовал отдельную модель для каждого выпадающего меню, в котором я нуждаюсь - я не знаю, так ли это хорошая идея сейчас, когда у меня их 35.У меня также есть 11 accepts_nested_attributes_for / cocoon gem partials, что после загрузки страницы супер, но я подозреваю, что 11 различных партиалов замедляют работу.

Я кеширую страницу, которая помогает, и в производстве это намного быстрее - 8 секунд - но все еще не совсем приемлемо.

Как мне идеально структурировать эту длинную форму?Я не могу думать, что это RESTful разделить метод редактирования / обновления.Или, если структура в порядке, что я могу сделать, чтобы улучшить производительность?Как я уже сказал, я кеширую, и в представлении нет никаких находок.Контроллер довольно обычный, хотя в модели есть много вычислений.

Вот фрагмент.Заранее большое спасибо за любые мысли.

%a{:name => "Measurements"}
- f.inputs :name => "Measurements", :id => "main" do
  %li.tip 
    = tooltip(:descriptivedetail_productcomposition_productcomposition, :hover)
  = f.input :descriptivedetail_productcomposition_productcomposition, :label => "Product composition", :as => :select, :collection => Productcomp.all, :value_method => :code 
  %li.list
    = link_to "Edit list", productcomps_path
  %br
  %li.tip 
    = tooltip(:descriptivedetail_productcomposition_productform, :hover)
  = f.input :descriptivedetail_productcomposition_productform, :label => "Product form", :as => :select, :collection => Productform.all, :value_method => :code 
  %li.list
    = link_to "Edit list", productforms_path
  %br
  %li.tip 
    = tooltip(:descriptivedetail_primarycontenttype, :hover)
  = f.input :descriptivedetail_primarycontenttype, :label => "Content type", :as => :select, :collection => Contenttype.all, :value_method => :code 
  %li.list
    = link_to "Edit list", contenttypes_path
  %br  
  %li.tip
    = link_to_add_association 'Add measurement', f, :measurements
    = f.semantic_fields_for :measurements do |measurement|
      = render 'measurement_fields', :f => measurement
  %br
  %li.tip
    = link_to_add_association 'Add extent', f, :extents
    = f.semantic_fields_for :extents do |extent|
      = render 'extent_fields', :f => extent
  %br
%a{:name => "Supply"}
- f.inputs :name => "Supply", :id => "main" do   
  %li.tip
    = link_to_add_association 'Add supply info', f, :supplies
    = f.semantic_fields_for :supplies do |supply|
      = render 'supply_fields', :f => supply
  %br
%a{:name => "Rights"}
- f.inputs :name => "Rights", :id => "main" do   
  %li.tip
    = link_to_add_association 'Add rights info', f, :rights
    = f.semantic_fields_for :rights do |right|
      = render 'right_fields', :f => right
  %br  
%a{:name => "Related"}
- f.inputs :name => "Related", :id => "main" do   
  %li.tip
    = link_to_add_association 'Add related product info', f, :relatedproducts
    = f.semantic_fields_for :relatedproducts do |relatedproduct|
      = render 'relatedproduct_fields', :f => relatedproduct
  %br

Пример частичного:

.nested-fields
  = f.inputs do
    %br  
    %li.tip 
      = tooltip(:descriptivedetail_measure_measuretype, :hover)
    = f.input :descriptivedetail_measure_measuretype, :label => "Measure type", :as => :select, :collection => Measuretype.all, :value_method => :code 
    %li.list
      = link_to "Edit list", measuretypes_path
    %br
    %li.tip 
      = tooltip(:descriptivedetail_measure_measurement, :hover)
    = f.input :descriptivedetail_measure_measurement, :label => "Measurement"
    %li.tip
      .links
    %br  
    %li.tip 
      = tooltip(:descriptivedetail_measure_measureunitcode, :hover)
    = f.input :descriptivedetail_measure_measureunitcode, :label => "Unit", :as => :select, :collection => Measureunit.all, :value_method => :code 
    %li.list
      = link_to "Edit list", measureunits_path
    %br
      = link_to_remove_association "Remove measurement", f
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...