• #38 楼 @_samqiu 一眼就被你看出来了,Redmine 你也接触过?^_^

  • #36 楼 @_samqiu php 我没接触过,所以领会不深,我在一个 view 页面里面的代码头部加了一下你给的语句,报错信息如下:

    Started GET "/wktime/edit?project_Id=2&startday=2013-04-21&tab=wktime&user_id=3" for 127.0.0.1 at 2013-07-16 11:34:56 +0800 Processing by WktimeController#edit as HTML Parameters: {"project_Id"=>"2", "startday"=>"2013-04-21", "tab"=>"wktime", "user_id"=>"3"} Current user: xwj (id=5) Rendered plugins/redmine_wktime/app/views/wktime/edit.html.erb within layouts/base (46.9ms) Completed 500 Internal Server Error in 297ms

    ActionView::Template::Error (undefined local variable or method current_user' for #<#<Class:0x39bab70>:0x3ea60a8>): 1: <%= debug current_user %> 2: 3: <%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %> 4: plugins/redmine_wktime/app/views/wktime/edit.html.erb:1:inplugins_redmine_wktime_app_views_wktime_edit_html_erb__393893685_32842176' actionpack (3.2.13) lib/action_view/template.rb:145:in block in render' activesupport (3.2.13) lib/active_support/notifications.rb:125:ininstrument' actionpack (3.2.13) lib/action_view/template.rb:143:in `render'

    你给的这句话的添加是不是有讲究的?

  • #20 楼 @Rei 你昨天发给我的那个 IDE 地址,里面是不是有工具下载,这个工具大么?你手上有么?方便发给我么?

  • #31 楼 @luikore 谢谢你,照你说的改了^_^

  • #32 楼 @ery 用 windows 系统是不是就不能用 pry 调试?要把 ruby 学好还要学会用 linux,看来是个大学问。

  • #28 楼 @luikore 路径下是有几个新生成的文件夹。

    是安装的时候,开头出现的那句话 WARNING: Error fetching data: too many connection resets (http://production.s3. rubygems.org/specs.4.8.gz) 还有安装过程中出现的类似语句对整体有影响么?

    unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping

  • #23 楼 @luikore 哦,这下明白 heliang7 为啥说远离 windows 了,那是不是也就意味着 pry 不能在 windows 下用?

  • #22 楼 @hooopo 水平低,所以。。。 看在女流之辈的份上,请多多包涵。

  • #17 楼 @hooopo 你的意思,我问的一系列问题太菜了?

  • #13 楼 @blacktulip 谢谢你的帮助,你发的这个链接是怎么安装和使用 pry 的介绍是吧,我在我的机器上用 执行了开头的两个命令,出现这样的信息,是不是表示我机器上还没有 pry?

    C:\Sites\redmine-2.3.0>gem install pry pry-doc WARNING: Error fetching data: too many connection resets (http://production.s3. rubygems.org/specs.4.8.gz) Fetching: slop-3.4.4.gem (100%) Fetching: method_source-0.8.1.gem (100%) Fetching: win32console-1.3.2-x86-mingw32.gem (100%) Fetching: pry-0.9.12.2-i386-mingw32.gem (100%) Successfully installed slop-3.4.4 Successfully installed method_source-0.8.1 Successfully installed win32console-1.3.2-x86-mingw32 Successfully installed pry-0.9.12.2-x86-mingw32 Fetching: yard-0.8.6.2.gem (100%) Fetching: pry-doc-0.4.6.gem (100%) Successfully installed yard-0.8.6.2 Successfully installed pry-doc-0.4.6 6 gems installed Installing ri documentation for slop-3.4.4... Installing ri documentation for method_source-0.8.1... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/method_source.rb, skipping Installing ri documentation for win32console-1.3.2-x86-mingw32... Installing ri documentation for pry-0.9.12.2-x86-mingw32... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry/terminal.rb, skipping Installing ri documentation for yard-0.8.6.2... Installing ri documentation for pry-doc-0.4.6... unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping Installing RDoc documentation for slop-3.4.4... Installing RDoc documentation for method_source-0.8.1... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/method_source.rb, skipping Installing RDoc documentation for win32console-1.3.2-x86-mingw32... Installing RDoc documentation for pry-0.9.12.2-x86-mingw32... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry/terminal.rb, skipping Installing RDoc documentation for yard-0.8.6.2... Installing RDoc documentation for pry-doc-0.4.6... unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping

    C:\Sites\redmine-2.3.0>rvm gemset use global 'rvm' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    C:\Sites\redmine-2.3.0>

  • #15 楼 @heliang7 “远离 windows”?为何?

  • #3 楼 @Rei 谢谢你,我这里用 chrome 打开你发的这个网站很慢很慢。不知道怎么回事。

  • #11 楼 @luikore log 目录下有个文件时间是最新的,打开看里面的内容就和我前面贴出来的图上的 cmd 窗口的内容一致。

    你说的“插 binding.pry 比 debug 好用”,能在说的详细些么,我还没理解。:$

  • #4 楼 @heliang7 你帖子上指的控制台 是不是是我现在用来看 puts 结果的地方?

  • #5 楼 @luikore 看你帖子上说的 $stderr.puts 我试了一下,还是打印不出来,你说的重定向到日志,怎么找这个日志文件?

  • #1 楼 @chinakr 谢谢你的回复,你给的这个链接,我先收藏先,慢慢学习,对于目前我的水平,这个帖子对我还有点深。 我现在想要的东西是能像一些开发工具那样,能对代码进行单步调试的,因为要修改代码,想用这种调试工具应该要比我现在无头苍蝇般的瞎 puts 好一些。😦

  • #29 楼 @zj0713001 收到你的回复,感动 ing,很感谢你在忙碌的工作中这么热心的帮助我,这块东西对于初学的我而言,感觉牵涉的东西纵横交错,有不少想请教的,在这里都贴出来么怕影响版面,所以之前问你是否有其他联系方式,方便进一步请教。😊

  • #26 楼 @zj0713001 问个问题,这段代码中 set_project_issues(@xxxx),依你看是做什么用?

    
    set_project_issues(@entries)
       if @entries.blank? && !params[:prev_template].blank?
           @prev_entries = prevTemplate(@user.id)
           if !@prev_entries.blank?
           set_project_issues(@prev_entries)
           @prev_template = true
           end
       end
    
    

    还有第二个问题,我在之前我贴出来的那个 view 的 erb 文件中看到这段代码,是不是就是引用@prev_template 的地方

    
    
    <% if !entry.blank? %>
                       <% if !issueWritten %>
                           <% # this is a new Row %>
                           <% # close the previously opened row first %>
                           <%= render :partial => 'edit_hours', :locals => {:entry => nil, :isTemplate => false,
                               :padAt => 'end', :padTill => 8}%>
    
                           <%= render :partial => 'edit_issues2', :locals => {:entry => entry, :isTemplate => false}%>     
                           <% issueWritten = true %>
                       <% end %>
                       <% # fill the days till the current day %>
                       <%= render :partial => 'edit_hours', :locals => {:entry => nil, :isTemplate => false, 
                               :padAt => 'begin', :padTill => i+1}%>
                       <%= render :partial => 'edit_hours', :locals => {:entry => entry, :isTemplate => false, 
                       :padAt => 'begin', :padTill => i+2}%>   
                       <% thours[i] += entry.hours unless @prev_template%>
                       <% @total_hours += entry.hours unless @prev_template%>
                       <% currencySym = controller.getUnit(entry) %>
                   <% end %>
               <% end %>
               <% # write only the firt row for previous week template
                 break if @prev_template %>
           <% end %>
       <% end %>
    
    
  • #26 楼 @zj0713001 难关攻破了,我的 ruby 学习之路估计就可以出师了,@zj0713001 ,再帮帮女流一把如何。

  • #24 楼 @zj0713001 第二个问题,凭我目前的能力还欠缺:( 首先感谢你这么热心的帮助我,弱弱的问一下,你用聊天工具不?能否求一个,方便我向你进一步请教。

  • #22 楼 @zj0713001 粗心,没注意_和。的区别,照你说的改了,还是老样子。

  • #20 楼 @zj0713001 你说“那你的代码里就得写是 @selected_pro.id 而不是 @selected_pro_id

    你的意思是我在 prevTemplate 函数里面 " and project_id=#{@selected_pro_id}"+

    这句话应该这样? " and project_id="+ @selected_pro_id+

  • #18 楼 @zj0713001 对于第一,我在一个 edit.html.erb 代码里加了这行代码,是不是就能传递参数过去?我查看 edit 页面的源代码,是能得到我要的 project_id 值的。

    
    <%= render :partial => 'row_template' %>
    <!--表单头-->
    <%= form_tag({:controller => controller.controller_name, :action => 'update'}, :method => :post, :id => 'wktime_edit') do %>
    
    <h2><%= l(:label_wktime) %></h2>
    <%=h hidden_field_tag('tab', "#{controller_name}") %>
    <!--add project_id Parameter-->
    <%=h hidden_field_tag('project_id', "#{@selected_project.id}") %>
    
    <%= render :partial => 'edit_header' %>
    
    
    
    

    对于第二。我还不理解 :$

  • #14 楼 @Juanito 看到了,谢谢你。之前在运行 ruby 的虚机上的 ie8 看,没有你图上标识的那个<>,用 chrome 浏览就一目了然了。

  • #13 楼 @lidashuang 谢谢你,用 chrome 看是好多了

  • @zj0713001 谢谢你的建议,之前我在网上也看了一些相关初级入门文档,因为有代码要改,想边调试边学习,所以也没有很充足的全面学习。对 ruby 这门语言是零基础,先前也不知道好的书和资料哪里有,加上英文不太好,看网上的资源悟性不高吧 :$

    **prevTemplate函数**
    
    def prevTemplate(user_id)   
            prev_entries = nil      
            noOfWeek = Setting.plugin_redmine_wktime['wktime_previous_template_week']
    
            if !noOfWeek.blank?
                entityNames = getEntityNames
    
    **这段是我修改后的sql语句增加了一个project_id 项目id的结果集删选**
    
                sqlStr = "select t.* from " + entityNames[1] + " t" + 
                        " inner join (select " + getDateSqlString('spent_on') + " as startday" +
                        " from  " + entityNames[1] + " where user_id = " + user_id.to_s +
                        " group by startday order by startday desc limit " + noOfWeek.to_s + ") as v" +
                        " on " + getDateSqlString('t.spent_on') + " = v.startday where user_id = " + user_id.to_s + 
                        " and project_id=#{@selected_pro_id}"+
                        " order by t.project_id, t.issue_id, t.activity_id"
    
    =begin
    **这段是原始最初的sql语句**
        ##oldsql
                sqlStr = "select t.* from " + entityNames[1] + " t" + 
                        " inner join (select " + getDateSqlString('spent_on') + " as startday" +
                        " from  " + entityNames[1] + " where user_id = " + user_id.to_s +
                        " group by startday order by startday desc limit " + noOfWeek.to_s + ") as v" +
                        " on " + getDateSqlString('t.spent_on') + " = v.startday where user_id = " + user_id.to_s +
                        " order by t.project_id, t.issue_id, t.activity_id"
    =end        
                prev_entries = TimeEntry.find_by_sql(sqlStr)
            end
            prev_entries        
    
        end
    
    

    修改页面的 view 嵌套了好几个页面,我把自己分析的觉得是主要的一张.erb 文件帖上来。

    
    <% 
    @wday_index = 1 
    @trOpen = false
    @row = 0
    @total_hours = 0.0
    thours = nums = Array[0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0]
    prev_entry = nil
    entry = nil 
    currencySym = ""
    %>
    
    <div class="wk-contextual">
    <% if @editable %>
        <%= link_to l(:button_add_row), "javascript:addRow();projectChanged(document.getElementsByName('time_entry[][project_id]'),0);", :class => 'icon icon-time-add' %>
    <% end %>
    </div>
    
    <table id="issueTable" class="list time-entries">
    <thead>
    <tr>
        <%= render :partial => 'issue_header'%>
    </tr>
    </thead>
    <tbody>
    
    <% unless entries.blank?
        col_values = []
        matrix_values = []
        weeklyHash = getWeeklyView(entries, controller.getUnitLabel, false)
        weeklyHash.each do |key, matrix|
            matrix.each do |rows|
                issueWritten = false
                rows.each.with_index do |entry, i|
    %>
    
    
                    <% if !entry.blank? %>
                        <% if !issueWritten %>
                            <% # this is a new Row %>
                            <% # close the previously opened row first %>
                            <%= render :partial => 'edit_hours', :locals => {:entry => nil, :isTemplate => false,
                                :padAt => 'end', :padTill => 8}%>
    
                            <%= render :partial => 'edit_issues2', :locals => {:entry => entry, :isTemplate => false}%>     
                            <% issueWritten = true %>
                        <% end %>
                        <% # fill the days till the current day %>
                        <%= render :partial => 'edit_hours', :locals => {:entry => nil, :isTemplate => false, 
                                :padAt => 'begin', :padTill => i+1}%>
                        <%= render :partial => 'edit_hours', :locals => {:entry => entry, :isTemplate => false, 
                        :padAt => 'begin', :padTill => i+2}%>   
                        <% thours[i] += entry.hours unless @prev_template%>
                        <% @total_hours += entry.hours unless @prev_template%>
                        <% currencySym = controller.getUnit(entry) %>
                    <% end %>
                <% end %>
                <% # write only the firt row for previous week template
                  break if @prev_template %>
            <% end %>
        <% end %>
    
    <% else -%>
        <% # if there are no entries, put an empty row%>
        <% currencySym = controller.getUnit(nil) %>
        <%= render :partial => 'edit_issues2', :locals => {:entry => nil, :isTemplate => false}%>
    <% end %>
    
        <% # pad any incomplete days %>
        <%= render :partial => 'edit_hours', :locals => {:entry => nil, :isTemplate => false,
            :padAt => 'end', :padTill => 8}%>
    
        <!-- row for putting the total -->
        <tr>
        <td class="project"></td>
        <td class="issue"></td>
        <td class="activity"></td>  
        <td class="comments"></td>
        <td ></td> <!-- for currency -->
        <td></td>
        <td></td>
        <% thours.each_with_index do |th,i| %>      
            <td align="center"><%= currencySym %>&nbsp;<span id=<%= "day_total_#{i+1}" %>><%= ("%.2f" % th) %></span></td>
        <% end %>
        <td>    
        <b> <%= l(:label_total) %>: <%= currencySym %>&nbsp;<span id="total_hours"><%= ("%.2f" % @total_hours) %></span></b>
        <%=h hidden_field_tag('total', ("%.2f" % @total_hours) ) %>
        <%=h hidden_field_tag('unit', currencySym) %>
        </td>
        </tr>   
    
        <% if controller.showWorktimeHeader %>
            <!-- Remaining Hours -->
            <%= render :partial => 'worktime_header', :locals => {:str => 'remaining_hours', :isEditable => false, :value => '0.0'}%>
        <% end %>
    </tbody>
    </table>
    
    <% if @wktime.nil? || @wktime.status == 'n' || @wktime.status == 'r' %>
            <%= submit_tag l(:button_save), :id => 'wktime_save', :name => 'wktime_save',  :disabled => !(@row > 0)%>
        <% if !Setting.plugin_redmine_wktime[:wktime_use_approval_system].blank? &&
                Setting.plugin_redmine_wktime[:wktime_use_approval_system].to_i == 1 %>     
                <%= submit_tag l(:button_submit),:id => 'wktime_submit', :name => 'wktime_submit', :onclick => "return validateMinhour('#{controller.minHour}','#{getNonWorkingDayColumn()}');" , :disabled => !(@row > 0)%>
        <% end %>
    <% end %>
    <% if !Setting.plugin_redmine_wktime[:wktime_use_approval_system].blank? &&
        Setting.plugin_redmine_wktime[:wktime_use_approval_system].to_i == 1 %>
        <% if !@wktime.nil? && @wktime.status == 's' %>
            <%= submit_tag l(:button_wk_unsubmit), :name => 'wktime_unsubmit', :disabled => !(@row > 0)%>
    
            <% if !@manage_projects.blank? &&
            (@user.id != User.current.id ||(!Setting.plugin_redmine_wktime[:wktime_own_approval].blank? && Setting.plugin_redmine_wktime[:wktime_own_approval].to_i == 1)) %>
                <%= submit_tag l(:button_wk_approve), :name => 'wktime_approve', :disabled => !(@row > 0)%>
                <%=h hidden_field_tag('wktime_notes', "") %>
                <% # the jquery dialog box doesn't port the reject button value%>
                <%=h hidden_field_tag('hidden_wk_reject', "") %>
                <%= submit_tag l(:button_wk_reject), :name => 'wktime_reject', :disabled => !(@row > 0),
                    :onclick => "return showNotes();" %>
            <% end %>
        <% elsif  !@wktime.nil? && @wktime.status == 'a' %>
            <% if !@manage_projects.blank? && (@user.id != User.current.id ||(!Setting.plugin_redmine_wktime[:wktime_own_approval].blank? && Setting.plugin_redmine_wktime[:wktime_own_approval].to_i == 1)) %>
                <%= submit_tag l(:button_wk_unapprove), :id => 'wktime_unapprove', :name => 'wktime_unapprove'%>
            <% end %>
        <% end %>
    <% end %>
    
    <div class="splitcontentright">
    <div class="contextual">
    <% if @editable %>
        <%= link_to l(:button_add_row), "javascript:addRow();projectChanged(document.getElementsByName('time_entry[][project_id]'),0);", :class => 'icon icon-time-add' %>
    <% end %>
    </div>
    </div>
    <%= context_menu time_entries_context_menu_path %>
    
    
    
    
    
  • @juanito 你说的 这句话,我没理解 :$,再弱弱的问一下。 你也可以透過點擊頁面的 <> 取得 raw markdown。

  • @Juanito 谢谢你这么详细的解释,感动 ing... ^_^

  • @levan 我用 ie8

  • @juanito,不好意思,对 ruby 这门技术还不太了解,你说的“Markdown 語法幫助”,之前不知道, 在你说回复框后,我看到这行字“按“M”键查看更多 帮助。”

    我按 m 没反应,点击“帮助”超链接,弹出来的框是偏移的,文字内容看不完整。