首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Request-URI在REDMINE时间表插件中过长

Request-URI在REDMINE时间表插件中过长
EN

Stack Overflow用户
提问于 2015-10-05 05:25:58
回答 1查看 506关注 0票数 1

我在红请求-URI太长,请求的网址的长度超过了这个服务器的容量限制。当我试图选择在时间表插件中的csv导出时间表报告。我该怎么解决这个问题请告诉我

EN

回答 1

Stack Overflow用户

发布于 2016-05-19 07:37:08

问题在于方法。您正在尝试检索url中的太多参数,Apache (或其他类似的参数)默认限制在2000个字符。在我的例子中,我无法访问Apache服务器,因此不能选择更改.conf文件。

查看存储库的分叉,我发现了一个已经解决了这个问题的人。以下是SashaH的拉请求链接。这个拉请求是相当新的,所以还没有提交。

只需按指示更改代码,插件就会按您的要求工作:

app/helpers/timesheet_helper.rb

代码语言:javascript
复制
   :timesheet => timesheet.to_param)
   end

-  def link_to_csv_export(timesheet)
-    link_to('CSV',
-      {
-        :controller => 'timesheet',
-        :action => 'report',
-        :format => 'csv',
-        :timesheet => timesheet.to_param
-      },
-      :method => 'post',
-      :class => 'icon icon-timesheet')
+  def form_for_csv_export(timesheet)
+    params_like_decode_url = CGI.unescape({:timesheet => timesheet.to_param}.to_query)
+    inputs = ""
+    form = form_tag :controller => 'timesheet', :action => 'report', :format => 'csv' do
+      params_like_decode_url.split("&").each do |param|
+        param_arr = param.split("=")
+        inputs << hidden_field_tag(param_arr.first, param_arr.last, :id => "")
+      end
+      inputs << submit_tag("CSV")
+      inputs.html_safe
+    end
+    form.html_safe
   end

   def toggle_arrows(element, js_function)

app/models/timesheet.rb

代码语言:javascript
复制
   def to_csv
     out = "";
+
+    handle_time_entries = {}
+    time_entries.each do |k,v|
+      if k.is_a? String
+          handle_time_entries[k] = v
+          next;
+      end
+      handle_time_entries[k.name] = v
+    end
+
+    time_entries = handle_time_entries
     FCSV.generate(out, :encoding => 'u', :force_quotes => true) do |csv|
       csv << csv_header

 @@ -314,7 +325,7 @@ def time_entries_for_user(user, options={})

     return TimeEntry.includes(self.includes).
       where(self.conditions([user], extra_conditions)).
-      order('spent_on ASC')
+      order('spent_on ASC').references(self.includes)
   end

   def fetch_time_entries_by_project

app/views/timesheet/report.html.erb

代码语言:javascript
复制
 <div class="contextual">
-  <%= link_to_csv_export(@timesheet) %>
+  <%= form_for_csv_export(@timesheet) %>
   <%= permalink_to_timesheet(@timesheet) %>
 </div>

init.rb

代码语言:javascript
复制
 require 'redmine'

 ## Taken from lib/redmine.rb
-#if RUBY_VERSION < '1.9'
-#  require 'faster_csv'
-#else
-#  require 'csv'
-#  FCSV = CSV
-#end
+if RUBY_VERSION < '1.9'
+ require 'faster_csv'
+else
+ require 'csv'
+ FCSV = CSV
+end

 if Rails::VERSION::MAJOR < 3
   require 'dispatcher'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32941792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档