31 lines
547 B
Ruby
31 lines
547 B
Ruby
|
|
class WorkController < ApplicationController
|
||
|
|
def index
|
||
|
|
if params[:homie_id]
|
||
|
|
work = Work.where(homie_id: params[:homie_id].to_i).all.order(created_at: :desc)
|
||
|
|
else
|
||
|
|
work = Work.all.order(created_at: :desc)
|
||
|
|
end
|
||
|
|
|
||
|
|
json_response work
|
||
|
|
end
|
||
|
|
|
||
|
|
def create
|
||
|
|
work = Work.new(work_params)
|
||
|
|
|
||
|
|
if work.save
|
||
|
|
json_response ok: true
|
||
|
|
else
|
||
|
|
error_response(:bad_request)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
def work_params
|
||
|
|
params.require(:work).permit(
|
||
|
|
:description,
|
||
|
|
:amount,
|
||
|
|
:homie_id
|
||
|
|
)
|
||
|
|
end
|
||
|
|
end
|