rails:3650
From: dezawa <dezawa@a...>
Date: Fri, 14 Oct 2011 10:27:48 +0900
Subject: [rails:3650] Re: selectが多すぎて開くのが重い、何とかならないか
出沢です CRCさんのおすすめにしたがってソースをpostします。 methodは関連する所だけ抜き出せば良いのですが、viewは そのままなので、全体で150行程度になります、済みません。 実測 DBのアクセス 7.6ms Render 1474.7ms Completed in 1837ms なのですが、ブラウザでの表示完了 に10秒 HTMLをファイルに取って表示させると 7秒 表示オンリーにしたときに表示完了 に 3秒 ==== Controller の抜粋 PlanLabels = [ [:id ,"ID","",:ro,2], [:jun ,"優先順","",:text,2], [:lot_no ,"番号","",:text], [:mass ,"**数","",:text,2], [:person_id ,"**名","",:personname], #Ajax], [:meigara ,"**","",:text], [:ope2 ,"***","",:ro], #:text], [:plan_ope1_from ,"","",:datetimero,7], [:plan_ope1_to ,"","",:datetimero,7], [:plan_ope2_from ,"","",:datetimero,7], [:plan_ope2_to ,"","",:datetimero,7], [:plan_ope3_from ,"","",:datetimero,7], [:plan_ope3_to ,"","",:datetimero,7], [:plan_ope4_from ,"","",:datetimero,7], [:plan_ope4_to ,"","",:datetimero,7], [:result_ope1_from ,"","",:datetime,8], [:result_ope1_to ,"","",:datetime,8], [:result_ope2_from ,"","",:datetime,8], [:result_ope2_to ,"","",:datetime,8], [:result_ope3_from ,"","",:datetime,8], [:result_ope3_to ,"","",:datetime,8], [:result_ope4_from ,"","",:datetime,8], [:result_ope4_to ,"","",:datetime,8] ] def edit @sortkey = (params[:sort] || 'jun' ) @TYTLE = "計画修正" @labels = Labels2 @RunTimeLabels=RunTimeLabels @plabels= PlanLabels @personnames = Person.all(:conditions => "id < 40",:select => "name,id").map{|p| [p.name,p.id]} @model = Schedule.find( params[:id])# ,:include => {:plans => :person}) plan_sort(@sortkey) end === Controller抜粋 ここまで === ===================== edit.erb ===================== <h2>計画立案・修正</h2> <%= error_messages(@model.errors) %> <table><%# subコマンド、統計、累積の表示 %> <tr> <td valain=top><%# subコマンド %> <table><tr><TD>立案番号 <%= @model.id %></td></tr> <tr><td><%= button_to 'CSVダウンロード ',:action=>:csv_download,:id=>@model.id %></td></tr> <tr> <td><%= form_tag :action => :doc_out,:id=>@model.id %> <%= submit_tag '作業指示書' %> 期間 </td> </tr> <tr><td> <input type='text' name='doc_from' size=4> 〜 <input type='text' name='doc_to' size=4> </form> </td> </tr> <% form_for(@model) do |f| %> <tr><td>立案期間<%= hidden_field_tag :id,value = @model.id %> <%= hidden_field_tag :sort,value = @sortkey %> <%= hidden_field :schedule,:sort,:value => @sortkey %> </td> </tr> <tr> <td> <%= edit_field( :schedule_skd,@model,:skd_from,:date,{:size=>7}) -%>〜 <%= edit_field( :schedule_skd,@model,:skd_to,:date,{:size=>7})%> </td> </tr> </table> </td> <td><%= timeline %></td> <%# 各工程の予定、実績、空き時間などの表 -%> <td><%= runtimeline(true) %></td> <%# 各工程の累積時間の表 -%> </tr> </table> <table><tr><td><font size=2>計画</td> <td><%= submit_tag '立案実行' %><%= hidden_field_tag :id,value = @model.id %></td> <td><%= link_to '表示',:action =>:show, :id=>@model.id,:sort =>@sortkey -%> </td> <% @sort.each{|sort| -%> <%= "<td>"+link_to( @Sort[sort],:action => :sort_edit,:sort => sort,:id=>@model.id)+"</td>" %> <% } -%> </tr></table> <%# 個別計画の表を描く -%> <%= render :partial => "edit_plans" %> <% end %> <%# of [form_for(@model) do |f| ] %> ============ _edit_plans.erb =========== <table border=1> <tr><% %w(ID 優先順 番号 **数 **名 ** ***).each{|lbl| -%> <td rowspan=2 align=center><%= lbl %></td> <% } -%> <% %w(予定 実績).each{|lbl| %><td colspan=8 align=center><nobr><%= lbl %>/開始,終了</td><% }%> </tr> <tr><% 2.times{ %w(** ** ** **).each{|lbl| %><td colspan=2 align=center><nobr><%= lbl %></td><%}%> <%}%> </tr> <% @plans.each do |plan| id = plan.id -%> <%= "<tr id='pro_#{id}'>" %><% @plabels.each{|items| -%> <td><nobr><%= edit_field_with_items :plan,plan,items,{:size=>5},'' %></td><% } -%> </tr> <% end -%> </table> <br /> ================== helper ================== def edit_field_with_items(domain,obj,items,opt={},htmlopt="") sym,lbl,hlpnsg,type,width = items opt[:size] = width ? width : opt[:size] ? opt[:size] : 2 case type when :ro ; htmlopt + obj.send(sym).to_s + "<input type='hidden' id='#{domain}_#{obj.id}_id' name='#{domain}[#{obj.id}][id]' value='#{obj.id}'>" when :datetimero ; str = obj.send(sym); htmlopt + (str ? str.strftime("%m/%d %H:%M") : "") when :text ; htmlopt + text_field(domain,sym,opt.merge(:index => obj.id,:value=>obj.send(sym))) when :datetime ; str = obj.send(sym) ; str = str ? str.strftime("%m/%d %H:%M"):"" htmlopt + text_field(domain,sym,opt.merge(:index => obj.id,:value=>str)) when :date ; str = obj.send(sym) ; str = str ? str.strftime("%Y/%m/%d"):"" htmlopt + text_field(domain,sym,opt.merge(:index => obj.id,:value=>str)) when :personname ;"\n<nobr>"+ (obj.person_id < 40 ? my_select( domain,:person_id,@personnames opt.merge(:index => obj.id,:value=>obj.person_id )) : obj.personname ) when :personnameAjax "<div id='pre#{obj.id}'>#{obj.personname}</div></td><td>"+ link_to_remote("修", :url => {:action => :select,:id=>obj.id,:per_id => obj.person_id}, :update => {:success => "per#{obj.id}" ,:failure => "error"} ) + "</div>" when :ope_select ; select_with_id(domain,sym , obj,obj.id,@select) else ; "\n"+send(type,obj,:index => obj.id) end end def my_select(object, method, choices, options = {}, html_options = {}) id = options.delete(:index) ; id = id ? "[#{id}]" : "" value = options.delete(:value) include_blank = options.delete(:include_blank) ? "<option value=''></option>\n" : "" "<select name='#{object}#{id}[#{method}]'>\n" + include_blank + choices.map{|lbl,val| selected = (val==value ? " selected='selected'" : "" ) "<option value='#{val}'#{selected}>#{lbl}</option>\n" }.join+"</select>\n" end -- ML: rails@r... 使い方: http://QuickML.com/
3635 2011-10-12 13:08 [dezawa@a... ] selectが多すぎて開くのが重い、何とかならないか 3636 2011-10-12 16:01 ┣[yukihiro.k@g... ] 3637 2011-10-12 17:31 ┃┣[masaki@h... ] 3638 2011-10-13 02:26 ┃┗[dezawa@a... ] 3639 2011-10-13 03:46 ┃ ┗[yukihiro.k@g... ] 3640 2011-10-13 04:04 ┣[ohyama@r... ] 3641 2011-10-13 05:32 ┃┗[dezawa@a... ] 3643 2011-10-13 09:25 ┃ ┗[dezawa@a... ] 3644 2011-10-13 15:39 ┃ ┗[masaki@h... ] 3645 2011-10-13 18:35 ┣[motoyuki.oya@g... ] 3646 2011-10-14 00:02 ┃┗[dezawa@a... ] -> 3650 2011-10-14 03:27 ┗[dezawa@a... ]