2016-11-17 4 views
0

모델 opening_times와 관련하여 모델 장소가 있습니다. 내 places_controller에서레일 - 형식 API 응답 시간

나는이있다 : DB에

def index 
    places = Place.all 

    if places 
    render json: { 
     status: :ok, 
     result: places.as_json(
     only: [ 
      :id, 
      :name, 
     ], 
     include: [ 
      { opening_times: {only: [:dayWeek, :open, :close]}}, 
     ] 
    ) 
    } 
    else 
    render json: { errors: 'invalid request' }, status: 422 
    end 
end 

private 
    def place_params 
    params.require(:place).permit(:user_id, :name) 
    end 

오픈과 가까운 열 time이다.

형식 시간을 %H:%M으로 되돌리려면 어떻게해야합니까?

+0

귀하의 places_controller – num8er

+0

의 전체를 추가하시기 바랍니다 @ num8er 내가 업데이 트되었습니다 ... – SaroVin

답변

0

나는 그래서 당신이 시도 할 수있는 문제

가있는 경우 해결하기 위해 무료로 채울 ... 3 년 이상의 RoR에서 개발하고 있지 않다 :

places = Place.all.map {|place| 
    place.opening_times.map! {|opening_time| 
    opening_time[:open].strftime! "%H:%M" 
    opening_time[:close].strftime! "%H:%M" 
    } 
}