handle adding work for homie

This commit is contained in:
Bilal
2020-09-19 04:46:17 +03:00
parent 6e0df8e7b7
commit ffde784e59
7 changed files with 70 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
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

View File

@@ -1,5 +1,6 @@
class Homie < ApplicationRecord
has_many :money_moves
has_many :work
belongs_to :chip
def self.cash(importance)

3
app/models/work.rb Normal file
View File

@@ -0,0 +1,3 @@
class Work < ApplicationRecord
belongs_to :homie
end