finished removing jbuilder

This commit is contained in:
Dan Elbert 2020-08-11 11:05:19 -05:00
parent 7dfa978c26
commit 3b5b95292c
21 changed files with 36 additions and 63 deletions

View File

@ -6,8 +6,6 @@ gem 'pg', '~> 1.2.2'
gem 'webpacker', '5.1.1'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'jbuilder', '~> 2.10'
gem 'oj', '~> 3.10.6'
gem 'kaminari', '~> 1.2.0'

View File

@ -61,7 +61,7 @@ GEM
msgpack (~> 1.0)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.1.6)
concurrent-ruby (1.1.7)
crass (1.0.6)
dalli (2.7.10)
database_cleaner (1.8.5)
@ -92,8 +92,6 @@ GEM
rspec (>= 2.99.0, < 4.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
@ -245,7 +243,6 @@ DEPENDENCIES
factory_bot_rails (~> 5.2.0)
guard (~> 2.16.2)
guard-rspec
jbuilder (~> 2.10)
kaminari (~> 1.2.0)
oj (~> 3.10.6)
pg (~> 1.2.2)

View File

@ -6,22 +6,14 @@ class NotesController < ApplicationController
# GET /notes.json
def index
@notes = Note.for_user(current_user)
render json: NoteSerializer.for(@notes)
end
# GET /notes/1
# GET /notes/1.json
def show
ensure_owner(@note)
end
# GET /notes/new
def new
@note = Note.new
end
# GET /notes/1/edit
def edit
ensure_owner(@note)
render json: NoteSerializer.for(@note)
end
# POST /notes

View File

@ -9,7 +9,7 @@ class TaskItemsController < ApplicationController
@task_item.task_list = @task_list
if @task_item.save
render :show, status: :created, location: [@task_list, @task_item]
render json: TaskItemSerializer.for(@task_item), status: :created, location: [@task_list, @task_item]
else
render json: @task_item.errors, status: :unprocessable_entity
end
@ -17,7 +17,7 @@ class TaskItemsController < ApplicationController
def update
if @task_item.update(task_item_params)
render :show, status: :ok, location: [@task_list, @task_item]
render json: TaskItemSerializer.for(@task_item), status: :ok, location: [@task_list, @task_item]
else
render json: @task_item.errors, status: :unprocessable_entity
end

View File

@ -5,10 +5,12 @@ class TaskListsController < ApplicationController
def index
@task_lists = TaskList.for_user(current_user).includes(:task_items).order(created_at: :desc)
render json: TaskListSerializer.for(@task_lists)
end
def show
ensure_owner(@task_list)
render json: TaskListSerializer.for(@task_list)
end
def create
@ -16,7 +18,7 @@ class TaskListsController < ApplicationController
@task_list.user = current_user
if @task_list.save
render :show, status: :created, location: @task_list
render json: TaskListSerializer.for(@task_list), status: :created, location: @task_list
else
render json: @task_list.errors, status: :unprocessable_entity
end
@ -25,7 +27,7 @@ class TaskListsController < ApplicationController
def update
ensure_owner(@task_list) do
if @task_list.update(task_list_params)
render :show, status: :ok, location: @task_list
render json: TaskListSerializer.for(@task_list), status: :ok, location: @task_list
else
render json: @task_list.errors, status: :unprocessable_entity
end

View File

@ -1,7 +1,7 @@
class TaskItem < ApplicationRecord
include DefaultValues
belongs_to :task_list
belongs_to :task_list, touch: true
validates :name, presence: true

View File

@ -1,4 +1,6 @@
class ApplicationSerializer
include Rails.application.routes.url_helpers
class CollectionSerializer < ApplicationSerializer
def initialize(items, serializer, opts = {})

View File

@ -0,0 +1,8 @@
class NoteSerializer < ApplicationSerializer
def serialize
{
**item_properties(:id, :content, :created_at),
url: note_path(item, format: :json)
}
end
end

View File

@ -0,0 +1,7 @@
class TaskItemSerializer < ApplicationSerializer
def serialize
{
**item_properties(:id, :task_list_id, :name, :quantity, :completed, :created_at, :updated_at)
}
end
end

View File

@ -0,0 +1,8 @@
class TaskListSerializer < ApplicationSerializer
def serialize
{
**item_properties(:id, :name, :created_at, :updated_at),
task_items: TaskItemSerializer.for(item.task_items).serialize
}
end
end

View File

@ -1,24 +0,0 @@
<div class="row">
<div class="col-xs-12">
<div class="page-header">
<h1>About</h1>
</div>
<p>
A Recipe manager. Source available from my Git repository at <a href="https://source.elbert.us/dan/parsley">https://source.elbert.us</a>.
</p>
<p>
Parsley is released under the MIT License. All code &copy; Dan Elbert 2016.
</p>
<p>
Food data provided by:<br/>
<cite>
US Department of Agriculture, Agricultural Research Service, Nutrient Data Laboratory. USDA National Nutrient Database for Standard Reference, Release 28. Version Current: September 2015. Internet: <a href="http://www.ars.usda.gov/nea/bhnrc/ndl">http://www.ars.usda.gov/nea/bhnrc/ndl</a>
</cite>
</p>
</div>
</div>

View File

@ -41,7 +41,7 @@
}
#app {
transition: opacity 0.5s ease-in;
transition: opacity 0.25s ease-in;
}
body.loading #app {

View File

@ -1,2 +0,0 @@
json.extract! note, :id, :content, :created_at
json.url note_url(note, format: :json)

View File

@ -1 +0,0 @@
json.array! @notes, partial: 'notes/note', as: :note

View File

@ -1 +0,0 @@
json.partial! "notes/note", note: @note

View File

@ -1,6 +0,0 @@
json.array! @tags do |t|
json.extract! t, :id, :name
end

View File

@ -1 +0,0 @@
json.extract! task_item, :id, :task_list_id, :name, :quantity, :completed, :created_at, :updated_at

View File

@ -1 +0,0 @@
json.partial! 'task_items/task_item', task_item: @task_item

View File

@ -1,3 +0,0 @@
json.extract! task_list, :id, :name, :created_at, :updated_at
json.task_items task_list.task_items, partial: 'task_items/task_item', as: :task_item

View File

@ -1 +0,0 @@
json.array! @task_lists, partial: 'task_lists/task_list', as: :task_list

View File

@ -1 +0,0 @@
json.partial! 'task_lists/task_list', task_list: @task_list