2012-12-18 2 views
0

datetime 형식 인 기한 열이있는 경우 .strftime을 호출하면 어떻게됩니까?레일 3 - strftime

예를 들어, 내 쇼보기에서

<% @todos.each do |todo|%> 
    <%= todo.due.strftime("%h %d") %> 
<% end %> 

을하고 난 무기 호에 대한 정의되지 않은 메서드`의 strftime '를 얻을 :

내가 컨트롤러에서 내 공연 방법이 있습니다 NilClass :

@todos = ProjectTodo.for_project(params[:id])

참고 : 난 업데이트되거나 생성 된 날짜를 표시하지 않으려는 경우 형식이 지정된 날짜 만 표시하려고합니다.

답변

1

노력이 ..

<% @todos.each do |todo|%> 
<%= todo.due ? todo.due.strftime("%h %d") : nil %> 
<% end %> 


     If the date is there then it will convert to the given format else it will display nil. 
+0

BAM을! 그랬어. 자 .... 정확히 어떻게 작동합니까? :) –

+0

값이있는 기한이있는 표의 모든 행이 있는지 확인하십시오. – vijikumar

+0

모든 행에 기한 열에 값이있는 것은 아닙니다. –