2016-11-17 8 views
0

私はモデルopening_timesとの関係でモデルの場所を持っています。私places_controllerでRails - フォーマット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

私はRoRの上で開発していないよ3+年...何の問題

があるのであればあなたがこの試すことができます修正する自由記入:

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