From 14f0db807dc3502f413245b67914b924183ad7c3 Mon Sep 17 00:00:00 2001 From: Linda Date: Mon, 13 Apr 2020 10:21:48 -0500 Subject: [PATCH 1/5] edited favorties controller to the correct params syntax to add a favorite that will include the user and the mural --- app/controllers/favorites_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 622a017..4c36314 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -10,11 +10,10 @@ def show end def create - favorite = Favorite.create(user_id: params[:user_id], mural_id: params[:mural_id]) + puts params + puts '======================' + favorite = Favorite.create(user_id: params[:user]["id"], mural_id: params[:mural]["id"]) render json: favorite end - - # will eventuall need a create so i can create a favotire - end From 6dcb02e7e9e56d9a85f1271ed552c98416920804 Mon Sep 17 00:00:00 2001 From: Linda Date: Mon, 13 Apr 2020 19:43:51 -0500 Subject: [PATCH 2/5] reset the db. Currently trying to add a favorites ID to fetch and delete --- app/controllers/favorites_controller.rb | 4 ++++ app/controllers/users_controller.rb | 19 +++++++++++++++++-- app/models/user.rb | 3 +++ db/schema.rb | 11 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 4c36314..ca83b08 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -16,4 +16,8 @@ def create render json: favorite end + def destroy + Favorite.destroy(params[:id]) + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5523b6e..1dc66b9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,10 +28,25 @@ def create end end - - + def update + puts "-------------------------------------" + user= User.find(params[:id]) + if user.update(user_params) + render json: user + else + render json: {error: "Failed"} + end + end + + end +private + def user_params + params.require(:user).permit(:first_name, :last_name, :user_name) + # , favorite_murals: [:id, :artist_id, :mural_title, :year_installed, :description, :artists, :created_at, :updated_at] + + end diff --git a/app/models/user.rb b/app/models/user.rb index 9859867..0e5751f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,5 +4,8 @@ class User < ApplicationRecord has_secure_password validates :user_name, uniqueness: { case_sensitive: false } + # accepts_nested_attributes_for :favorite_murals + + # I need to research about uniqueness...what is current is for testing end diff --git a/db/schema.rb b/db/schema.rb index a1010ee..07a05b3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,14 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2020_04_01_161308) do From f0c850e3e249d28dbf39fb1b8a08bfbb246bb0ab Mon Sep 17 00:00:00 2001 From: Linda Date: Mon, 13 Apr 2020 22:53:22 -0500 Subject: [PATCH 3/5] the add favorite and delete favorite work --- app/controllers/favorites_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index ca83b08..bc8b79d 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -5,7 +5,7 @@ def index end def show - favorite = Favorite.find(params[:id]) + favorite = Favorite.find(params["id"]) render json: favorite end From 4e08a59b2febc8e0d1e8cd228a0ba578e0adfa4a Mon Sep 17 00:00:00 2001 From: Linda Date: Wed, 15 Apr 2020 16:15:45 -0500 Subject: [PATCH 4/5] added a create in the murals controller. Able to add murls to the backend now. --- app/controllers/murals_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/murals_controller.rb b/app/controllers/murals_controller.rb index 7924841..f94d00e 100644 --- a/app/controllers/murals_controller.rb +++ b/app/controllers/murals_controller.rb @@ -10,7 +10,12 @@ def show render json: mural end - def new + def create + + mural = Mural.create(mural_title: params[:mural_title], year_installed: params[:year_installed], description: params[:description], artists: params[:artists]) + + render json: mural + end end From 96d101743e1c57bf64a5e34e9a144714a9929374 Mon Sep 17 00:00:00 2001 From: Linda Date: Sun, 19 Apr 2020 11:14:55 -0500 Subject: [PATCH 5/5] extra save point --- app/controllers/murals_controller.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/murals_controller.rb b/app/controllers/murals_controller.rb index f94d00e..99e4408 100644 --- a/app/controllers/murals_controller.rb +++ b/app/controllers/murals_controller.rb @@ -11,11 +11,20 @@ def show end def create - + mural = Mural.create(mural_title: params[:mural_title], year_installed: params[:year_installed], description: params[:description], artists: params[:artists]) render json: mural end + def update + puts "***********-----------------***************" + mural = Mural.find(params[:id]) + mural.update(mural_title: params[:mural_title], year_installed: params[:year_installed], description: params[:description], artists: params[:artists] ) + + render json: mural + end + + end