From c6bfd1ad8b6a9bbfe9912659622db22dc4a80d74 Mon Sep 17 00:00:00 2001 From: Elizabeth Deutsch Date: Fri, 16 Jun 2017 09:54:27 -0700 Subject: [PATCH 1/4] added create to movie routes, create to movies_controller --- app/controllers/movies_controller.rb | 16 ++++++++++++++++ config/routes.rb | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..64b22505 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,6 +11,18 @@ def index render status: :ok, json: data end + def create + movie = Movie.new(movie_params) + puts params[:movie].to_hash + if movie.save + render status: :ok, json: { id: movie.id } + else + render status: :bad_request, json: { errors: movie.errors.messages } + end + # movie = Movie.create(movie_params) + # redirect_to movies_path + end + def show render( status: :ok, @@ -29,4 +41,8 @@ def require_movie render status: :not_found, json: { errors: { title: ["No movie with title #{params["title"]}"] } } end end + + def movie_params + params.require(:movie).permit(:title, :inventory, :overview, :release_date, :image_url) + end end diff --git a/config/routes.rb b/config/routes.rb index 54bf033e..8eff1ff6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ resources :customers, only: [:index] - resources :movies, only: [:index, :show], param: :title + resources :movies, only: [:index, :show, :create], param: :title post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in" From 7d3b65ab486bece3720748f322d729799a0a31af Mon Sep 17 00:00:00 2001 From: Tehut Getahun Date: Sat, 17 Jun 2017 13:58:55 -0700 Subject: [PATCH 2/4] added CORS origin permissions for local domain port:8081 --- config/application.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 9f8a6f91..6c5922ac 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,9 +17,15 @@ class Application < Rails::Application config.middleware.insert_before 0, Rack::Cors do allow do - origins '*' + origins '*', 'localhost/8081' resource '*', :headers => :any, :methods => [:get, :post, :put, :delete, :options] end +# Allow CORS (cross origin resource sharing) +# Read More: https://demisx.github.io/rails-api/2014/02/18/configure-accept-headers-cors.html + # config.Access-Control-Allow-Origin.action_dispatch.default_headers = { + # Access-Control-Allow-Origin = 'http://my-web-service-consumer-site.com' + # Access-Control-Request-Method = %w{GET POST OPTIONS}.join(",") + end end end From b1443ee567d46483f63572b98323ff7d93305bf5 Mon Sep 17 00:00:00 2001 From: Emma Claire Philippides Date: Wed, 21 Jun 2017 11:34:26 -0700 Subject: [PATCH 3/4] getting image to show up --- lib/movie_wrapper.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/movie_wrapper.rb b/lib/movie_wrapper.rb index 7bd05c0e..d8f19a73 100644 --- a/lib/movie_wrapper.rb +++ b/lib/movie_wrapper.rb @@ -32,7 +32,10 @@ def self.construct_movie(api_result) end def self.construct_image_url(img_name) - return BASE_IMG_URL + DEFAULT_IMG_SIZE + img_name + puts "BASE_IMG_URL" + img_url = BASE_IMG_URL + DEFAULT_IMG_SIZE + img_name + puts "constructed url for image: #{img_url}" + return img_url end end From 8be1e1cbd7e75cbeb87ce2f9d7b0c7c09a7a5d66 Mon Sep 17 00:00:00 2001 From: Elizabeth Deutsch Date: Fri, 23 Jun 2017 15:14:23 -0700 Subject: [PATCH 4/4] deleted some commented out lines --- app/controllers/movies_controller.rb | 3 +-- app/models/movie.rb | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 64b22505..28adefad 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -19,8 +19,7 @@ def create else render status: :bad_request, json: { errors: movie.errors.messages } end - # movie = Movie.create(movie_params) - # redirect_to movies_path + end def show diff --git a/app/models/movie.rb b/app/models/movie.rb index 0327a4d6..302369ee 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -10,6 +10,8 @@ def available_inventory def image_url orig_value = read_attribute :image_url + puts orig_value.class + # if orig_value == nil if !orig_value MovieWrapper::DEFAULT_IMG_URL else