2011-01-25 96 views
0

我有一些像這樣的代碼users_controller.rb,我需要打印線30號在development.log是否可以在開發記錄器中打印一行?

line#29 def selectrole 
line#30 @userrole = RolesUser.find(:all, :conditions =>["p.user_id = ? and p.status = ? ",session[:user_id], params['status']]) 
line#31 logger.debug print_line(30) 
line#32 end 

我可以看到30日線在我development.log這樣

@userrole = RoleUser.find(:all, :conditions => ["p.user_id = ? and p.status = ? ", 1234, 'Active']) 

寫「print_line」函數的方法是什麼?這是我的print_line代碼?

def print_line(file_name, line) 
    counter = 1 
    printline = "-------- NO SUCH LINE --------" 
    File.open(file_name, "r") do |infile| 
     while (line_text = infile.gets) 
     if counter == line 
      printline = "#{counter} :: " + line_text  
      break 
     end 
     counter += 1 
     end 
    end 
    printline 
end 

從這個功能我越來越喜歡這個

@userrole = RolesUser.find(:all, :conditions =>["p.user_id = ? and p.status = ? ",session[:user_id], params['status']]) 

是他們沒有辦法找到與它們各自的值替換變量?

+1

logger.debug 「富:#{} FOO」。我建議你使用調試器進行那種測試。它可以完全訪問所有變量。 – apneadiving 2011-01-25 07:09:48

回答

3

假設你知道你自己:conditions的內容主要有興趣,爲什麼不只是做這樣的事情:

def selectrole 
    conditions = ["p.user_id = ? and p.status = ? ",session[:user_id], params['status']] 
    logger.debug(conditions) 
    @userrole = RolesUser.find(:all, :conditions => conditions) 
end 
相關問題