2011-01-25 5 views
0

은 내가 몇 가지 코드이 users_controller.rb처럼, 나는이개발 로거에서 라인을 인쇄 할 수 있습니까?

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

처럼 내 development.log 파일에 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 라인에 라인 더 (30)를 인쇄하지 할 필요가있다 "print_line"함수를 작성하는 방법은 무엇입니까? 내 print_line 코드는 다음과 같습니다. 나는 그들의 어떤 식 으로든 찾아 각각의 값으로 변수를 대체 할 수 있나요이

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

처럼 무엇입니까이 함수

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 

?

+1

logger.debug "foo는 : # {foo는}". 그런 종류의 테스트에는 디버거를 사용하는 것이 좋습니다. 모든 변수에 대한 완전한 액세스를 가능하게합니다. – apneadiving

답변

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 
관련 문제