2011-01-25 71 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 
相关问题