Rails 3非常长,非常慢

时间:2011-06-17 16:43:28

标签: ruby-on-rails performance forms

我有一个很长的表格,有嵌套的表格字段。加载需要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

0 个答案:

没有答案