2013-11-20 3 views
0

start_date (정상 creation_date가 아님)이 내 문자열 날짜 (11-20-2013)의 모든 레코드를 1 주일 내에 가져오고 싶습니다.범위 날짜를 날짜 + 주일까지

레일스에서 ​​범위 지정을 사용하지 않으므로 여기에서 길을 잃어 버렸습니다. .where()를 사용해야합니까? 그렇다면이 기간에 start_date + 1 주를 어떻게 입력합니까?

내가 좋아하는 뭔가를 시도했다 : 던졌습니다

if params[:startdate] 
    group = Group.find_by_id(params[:group_id]).where(:start_date => params[:startdate]..params[:startdate] + 1.weeks) 
    end 

: 당신이 날짜 시간을 필요로 할 때 params[:startdate]이 문자열은 can't convert ActiveSupport::Duration into String

답변

1

때문에입니다.

당신은 후반 응답이

startdate = DateTime.parse(params[:startdate]) rescue nil 
if startdate 
    group = Group.find_by_id(params[:group_id]).where(:start_date => startdate..startdate + 1.weeks) 
else 
    # you get wrong startdate 
end 
+0

죄송 구문 분석을 시도 할 수 있습니다. # 'Group : 0x8623338>' – CaptainCarl

+0

'Group'은 모델 (클래스'ActiveRecord :: Base')입니까? – gotva

+0

예, 모델입니다. – CaptainCarl