新手问题 接触 ruby 不久,看代码一些地方看不明,不知这边的高手能帮一把么?

w_jie · 2013年07月11日 · 最后由 w_jie 回复于 2013年07月17日 · 5522 次阅读
def   edit
   respond_to do |format|
       format.html {
           @prev_template = false
           @new_custom_field_values = getNewCustomField
           setup
           findWkTE(@startday)
           @editable = @wktime.nil? || @wktime.status == 'n' || @wktime.status == 'r'
           @entries = findEntries()
           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
           render :layout => !request.xhr?
       } 
       format.api  {
       }
   end
 end

我猜测这块代码是某个修改页面显示相关的内容,我想对该修改页面调用的数据库查询结果集做修改调整,以上这段代码中没看到直接引用数据库查询结果,唯独看到这句“@prev_entries = prevTemplate(@user.id)”中prevTemplate函数定义中有 sql 语句,但是修改了相应的 sql 语句后,返回的查询结果集还是没有变化。 对这块代码理解的不深,大家能帮我看看,可能问题在哪里么?


     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

先排整齐吧,看帮助。

@chenge,不好意思,你说的看帮助,是指让我看 ruby 相关的帮助么?

@w_jie Markdown 語法幫助,在回復框框下面。

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

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

你用的什么浏览器?

···ruby 代码

最后是三个·符号

#4 楼 @w_jie 哈簡易得跟你說下,這是社區提供的優質功能,叫做 Markdown,是一種寫 HTML 的語法糖,高效使用 Markdown 排版精美,這個大牛自然就來回復你的問題了。

比如大段大段的代碼塊,請用:三個 ` 包起來,上下各留一個空行,像是這樣:

(空行) ```ruby 放超過一行的代碼 ``` (空行)

至於行文時引用到的變量名、函數名,用行內代碼包起來,語法是:

`a_method_name`

希望對你有幫助 :D

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

#9 楼 @w_jie 不會不會,改得不錯了,還有幾個小地方要注意下,我幫你改好了,我放在 GitHub 免費提供的 Gist 服務上面,你可以看看這裡,這是左邊這個文件的 Markdown 原始碼,你也可以透過點擊頁面的 <> 取得 raw markdown。 :)

我说真心的 楼主先看看书呗... 这样折磨自己多难受呢... 废话说完了 楼主再贴一下 prevTemplate 函数的内容 和 view 里面的代码吧 只有 controller 没法分析的

@juanito 你说的 这句话,我没理解 :$,再弱弱的问一下。 你也可以透過點擊頁面的 <> 取得 raw markdown。

还在用 ie8!!! , 给你推荐个

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 %>




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

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

#15 楼 @w_jie 有两个地方不明确 第一 prevTemplate 函数里面 你加的 product_id = @selected_pro_id 这里面 @selected_pro_id哪里来的? 第二 你的 controller 里面 @prev_entries 集合会被带到 view 可是你的 erb 里没发现这个集合的迭代

#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' %>



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

#19 楼 @w_jie 第一个问题 那你的代码里就得写是 @selected_pro.id 而不是 @selected_pro_id 第二个问题 @开头的变量 是可以从 controller 里带到 view 访问的 所以你的 view 里肯定是有地方把他显示出来 所以你找找@prev_template变量在 view 里哪里用到了 你先改下第一个问题 看看结果对不对...

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

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

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

#21 楼 @w_jie " and project_id=#{@selected_pro.id}"+ 是这样~

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

#23 楼 @w_jie 唉 完蛋艹了 那就的看看第二个问题了... 找找@prev_template在哪用到了...

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

#25 楼 @w_jie 唉 主要是看到留给你的这个烂程序 之前写这个的人就该枪毙 5 分钟...

#26 楼 @zj0713001 难关攻破了,我的 ruby 学习之路估计就可以出师了,@zj0713001 ,再帮帮女流一把如何。

#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 %>

#27 楼 @w_jie 额 周一再帮你看看行不行 今天比较忙... 好像我之前回的有问题 应该是找找@prev_entries在哪里用的... 你的整体代码的意思应该是有一个集合是@entries 还有一个集合是@prev_entries(之前的 entries?) 还有一个是 @prev_template(用来判断是不是有之前的?) 大体是这意思吧?然后你加的 product_id 是在@prev_entries这个集合的 sql 里面 是不是加错了地方哈~

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

#30 楼 @w_jie 发到论坛上就是能让大家看到哈 以后再有人有一样的问题就不用再问一遍了 可以给我发 email require 'base64'; Base64.decode64 'emowNzEzMDAxQGdtYWlsLmNvbQ=='

#31 楼 @zj0713001 收到,谢谢你^_^ 发论坛我是有点怕问题太多,影响广大观众,已经有人说我是十万个为什么了 :$

#31 楼 @zj0713001 先请教一下,根据你前几天回的帖,我调试了一下,发现你说的没错。edit 这段代码里面



def   edit
    respond_to do |format|
        format.html {
            @prev_template = false
            @new_custom_field_values = getNewCustomField
            setup
            findWkTE(@startday)
            @editable = @wktime.nil? || @wktime.status == 'n' || @wktime.status == 'r'
            @entries = findEntries()
            set_project_issues(@entries)
'这个if条件里面的内容没有执行因为 @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
================================================

            render :layout => !request.xhr?
        } 
        format.api  {
        }
    end
  end

我想查看 @entries结果集调用的 sql 语句,几天都没找到门,看到@entries集合调用了 finEntries 方法但是也没找到 sql 语句,我自己调试加了一个@selected_project.id参数,结果报错。又看了 findEntriesByCond 方法,看到它就完全不懂啥意思了:$


def findEntries
        setup
        # cond = getCondition('spent_on', @user.id, @startday, @startday+6, @selected_project.id) 
        cond = getCondition('spent_on', @user.id, @startday, @startday+6)        
        findEntriesByCond(cond)
    end

 def findEntriesByCond(cond)
        TimeEntry.find(:all, :conditions => cond,
            :order => 'project_id, issue_id, activity_id, spent_on')
    end

#33 楼 @hooopo 别说这话,你这一说,让我觉得更惭愧,我是问的有点多,你也是实话实说而已 :P 我前面那么一说只是自己觉得水平太菜,这么多不懂,没有说你的意思。

#34 楼 @w_jie 你木有找到 sql 是因为 findEntries()用了 activerecord 的 find 方法 你看下 guides 里面有~ 生成的 sql 你在 log 里能看到~

#36 楼 @zj0713001 你说的 guides 是什么?,没找到。

我找的 log 里面看不出 sql,麻烦你帮我看看

Connecting to database specified by database.yml OpenIdAuthentication.store is nil. Using in-memory store. Creating scope :sorted. Overwriting existing method Group.sorted. Creating scope :sorted. Overwriting existing method User.sorted. Started GET "/wktime/index?utf8=%E2%9C%93&getusers_url=%2Fwktime%2Fgetusers&tab=wktime&project_id=2&user_id=0&status=all&period_type=1&period=current_year" for 127.0.0.1 at 2013-07-17 13:26:01 +0800 Processing by WktimeController#index as HTML Parameters: {"utf8"=>"✓", "getusers_url"=>"/wktime/getusers", "tab"=>"wktime", "project_id"=>"2", "user_id"=>"0", "status"=>"all", "period_type"=>"1", "period"=>"current_year"} Current user: xwj (id=5) DEPRECATION WARNING: Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments. (called from initialize at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:28) DEPRECATION WARNING: Paginator#items_per_page will be removed. Use #per_page instead. (called from items_per_page at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:94) DEPRECATION WARNING: Paginator#current will be removed. Use .offset instead of .current.offset. (called from current at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:99) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered common/_tabs.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_date_range.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_list.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_te_index.html.erb (109.4ms) Rendered plugins/redmine_wktime/app/views/wktime/index.html.erb within layouts/base (265.6ms) Completed 200 OK in 2078ms (Views: 359.4ms | ActiveRecord: 46.9ms) Started GET "/wktime/edit?project_Id=2&startday=2013-04-21&tab=wktime&user_id=3" for 127.0.0.1 at 2013-07-17 13:26:09 +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/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_row_template.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_header.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row_header.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_issue_header.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues.html.erb (171.9ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_footer.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/edit.html.erb within layouts/base (203.1ms) Completed 200 OK in 328ms (Views: 234.4ms | ActiveRecord: 15.6ms) Connecting to database specified by database.yml OpenIdAuthentication.store is nil. Using in-memory store. Creating scope :sorted. Overwriting existing method Group.sorted. Creating scope :sorted. Overwriting existing method User.sorted. Started GET "/wktime/index?utf8=%E2%9C%93&getusers_url=%2Fwktime%2Fgetusers&tab=wktime&project_id=2&user_id=0&status=all&period_type=1&period=current_year" for 127.0.0.1 at 2013-07-17 13:29:03 +0800 Processing by WktimeController#index as / Parameters: {"utf8"=>"✓", "getusers_url"=>"/wktime/getusers", "tab"=>"wktime", "project_id"=>"2", "user_id"=>"0", "status"=>"all", "period_type"=>"1", "period"=>"current_year"} Current user: xwj (id=5) DEPRECATION WARNING: Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments. (called from initialize at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:28) DEPRECATION WARNING: Paginator#items_per_page will be removed. Use #per_page instead. (called from items_per_page at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:94) DEPRECATION WARNING: Paginator#current will be removed. Use .offset instead of .current.offset. (called from current at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:99) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered common/_tabs.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_date_range.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_list.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_te_index.html.erb (140.6ms) Rendered plugins/redmine_wktime/app/views/wktime/index.html.erb within layouts/base (406.2ms) Completed 200 OK in 2172ms (Views: 468.8ms | ActiveRecord: 78.1ms) Started GET "/wktime/index?utf8=%E2%9C%93&getusers_url=%2Fwktime%2Fgetusers&tab=wktime&project_id=2&user_id=0&status=all&period_type=1&period=current_year" for 127.0.0.1 at 2013-07-17 13:29:08 +0800 Processing by WktimeController#index as / Parameters: {"utf8"=>"✓", "getusers_url"=>"/wktime/getusers", "tab"=>"wktime", "project_id"=>"2", "user_id"=>"0", "status"=>"all", "period_type"=>"1", "period"=>"current_year"} Current user: xwj (id=5) DEPRECATION WARNING: Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments. (called from initialize at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:28) DEPRECATION WARNING: Paginator#items_per_page will be removed. Use #per_page instead. (called from items_per_page at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:94) DEPRECATION WARNING: Paginator#current will be removed. Use .offset instead of .current.offset. (called from current at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:99) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered common/_tabs.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_date_range.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_list.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_te_index.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/index.html.erb within layouts/base (15.6ms) Completed 200 OK in 47ms (Views: 31.2ms | ActiveRecord: 0.0ms) Started GET "/wktime/edit?project_Id=2&startday=2013-04-21&tab=wktime&user_id=3" for 127.0.0.1 at 2013-07-17 13:29:12 +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/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_row_template.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_header.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row_header.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_issue_header.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues.html.erb (62.5ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_footer.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/edit.html.erb within layouts/base (109.4ms) Completed 200 OK in 281ms (Views: 187.5ms | ActiveRecord: 31.2ms) Connecting to database specified by database.yml OpenIdAuthentication.store is nil. Using in-memory store. Creating scope :sorted. Overwriting existing method Group.sorted. Creating scope :sorted. Overwriting existing method User.sorted. Started GET "/wktime/index?utf8=%E2%9C%93&getusers_url=%2Fwktime%2Fgetusers&tab=wktime&project_id=2&user_id=0&status=all&period_type=1&period=current_year" for 127.0.0.1 at 2013-07-17 13:32:35 +0800 Processing by WktimeController#index as / Parameters: {"utf8"=>"✓", "getusers_url"=>"/wktime/getusers", "tab"=>"wktime", "project_id"=>"2", "user_id"=>"0", "status"=>"all", "period_type"=>"1", "period"=>"current_year"} Current user: xwj (id=5) DEPRECATION WARNING: Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments. (called from initialize at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:28) DEPRECATION WARNING: Paginator#items_per_page will be removed. Use #per_page instead. (called from items_per_page at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:94) DEPRECATION WARNING: Paginator#current will be removed. Use .offset instead of .current.offset. (called from current at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:99) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered common/_tabs.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_date_range.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_list.html.erb (31.2ms) Rendered plugins/redmine_wktime/app/views/wktime/_te_index.html.erb (109.4ms) Rendered plugins/redmine_wktime/app/views/wktime/index.html.erb within layouts/base (390.6ms) Completed 200 OK in 2203ms (Views: 437.5ms | ActiveRecord: 78.1ms) Started GET "/wktime/index?utf8=%E2%9C%93&getusers_url=%2Fwktime%2Fgetusers&tab=wktime&project_id=2&user_id=0&status=all&period_type=1&period=current_year" for 127.0.0.1 at 2013-07-17 13:32:39 +0800 Processing by WktimeController#index as / Parameters: {"utf8"=>"✓", "getusers_url"=>"/wktime/getusers", "tab"=>"wktime", "project_id"=>"2", "user_id"=>"0", "status"=>"all", "period_type"=>"1", "period"=>"current_year"} Current user: xwj (id=5) DEPRECATION WARNING: Paginator no longer takes a controller instance as the first argument. Remove it from #new arguments. (called from initialize at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:28) DEPRECATION WARNING: Paginator#items_per_page will be removed. Use #per_page instead. (called from items_per_page at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:94) DEPRECATION WARNING: Paginator#current will be removed. Use .offset instead of .current.offset. (called from current at C:/Sites/redmine-2.3.0/lib/redmine/pagination.rb:99) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_tab_content.html.erb (0.0ms) Rendered common/_tabs.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_date_range.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_list.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_te_index.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/index.html.erb within layouts/base (15.6ms) Completed 200 OK in 47ms (Views: 31.2ms | ActiveRecord: 0.0ms) Started GET "/wktime/edit?project_Id=2&startday=2013-04-21&tab=wktime&user_id=3" for 127.0.0.1 at 2013-07-17 13:32:42 +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/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_row_template.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_header.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row_header.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_issue_header.html.erb (15.6ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_wktime_cf_in_row.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues2.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_hours.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_issues.html.erb (109.4ms) Rendered plugins/redmine_wktime/app/views/wktime/_edit_footer.html.erb (0.0ms) Rendered plugins/redmine_wktime/app/views/wktime/edit.html.erb within layouts/base (156.2ms) Completed 200 OK in 281ms (Views: 171.9ms | ActiveRecord: 62.5ms)

#34 楼 @w_jie guides 特指 http://guides.ruby-china.org/ 你的服务是 production 启动的吧 sql 是不显示的...

#38 楼 @zj0713001 那怎么启动能显示 sql?

我真是弱爆了,基础用语都不知道.......@_@

#39 楼 @w_jie 笑了 一个眼睛大 一个眼睛小 你先看看 http://guides.ruby-china.org/active_record_querying.html 然后晚一点再帮你解决 rails s 启动就是 development 模式~

#40 楼 @zj0713001 你说的启动 development 模式是用这个命令?我这结果是不是失败?是命令不对么?

C:\Sites\redmine-2.3.0>rails s => Booting WEBrick => Rails 3.2.13 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/l ib/mysql2/client.rb:44:in connect': Access denied for user 'root'@'localhost' ( using password: NO) (Mysql2::Error) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2/client.rb:44:ininitialize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in new' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:inmysql2_conn ection' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in new_connection' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in checkout_new_connection' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in block (2 levels) in checkout' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in loop' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 .2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in block in checkout' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:inmon_s ynchronize'

需要 登录 后方可回复, 如果你还没有账号请 注册新账号