Created
June 19, 2014 20:15
-
-
Save brunoandradd/7e56c7ecd60c68352a0e to your computer and use it in GitHub Desktop.
Serialize.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomerSerializer < ActiveModel::Serializer | |
attributes :id, :name, :email | |
end | |
class SchedulingSerializer < ActiveModel::Serializer | |
attributes :id, :beauty_salon_id, :schedule_id, :customer_id, | |
:date_scheduling, :hour, :beauty_salon | |
has_many :services | |
def hour | |
object.hour.strftime('%H:%M') | |
end | |
def date_scheduling | |
object.date_scheduling.strftime('%d/%m/%Y') | |
end | |
def beauty_salon | |
object.beauty_salon.name | |
end | |
def services | |
object.services.select('id, name') | |
end | |
end | |
#controllers | |
class Api::VacanciesController < Api::ApplicationController | |
def by_date | |
@beauty_salon = BeautySalon.where(id: params[:beauty_salon_id]).first | |
@vacancies = @beauty_salon.vacancies(date_vacancies) | |
render json: @vacancies, each_serializer: VacancySerializer | |
end | |
private | |
def date_vacancies | |
@date_vacancies = | |
begin | |
Date.parse params[:date] | |
rescue | |
Date.today | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment