diff --git a/.ruby-version b/.ruby-version index 4560fb9..49cdd66 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.6.3 +2.7.6 diff --git a/app/controllers/guitars_controller.rb b/app/controllers/guitars_controller.rb new file mode 100644 index 0000000..92e9a6e --- /dev/null +++ b/app/controllers/guitars_controller.rb @@ -0,0 +1,24 @@ +class GuitarsController < ApplicationController + def index + render :json => [ + { + 'name':'guitar1', + 'url':'https://rukminim1.flixcart.com/image/416/416/acoustic-guitar/x/8/w/topaz-blue-signature-original-imaefec7uhypjdr9.jpeg?q=70', + 'price':'100', + 'description':'blablabla 1' + }, + { + 'name':'guitar2', + 'url':'https://shop.brianmayguitars.co.uk/user/special/content/Antique%20Cherry%20a.jpg', + 'price':'200', + 'description':'blablabla 2' + }, + { + 'name':'guitar3', + 'url':'https://cdn.mos.cms.futurecdn.net/Yh6r74b8CAj2jbdf2FAhq4-970-80.jpg.webp', + 'price':'300', + 'description':'blablabla 3' + } + ] + end + end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb deleted file mode 100644 index d1af404..0000000 --- a/app/controllers/user_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class UserController < ApplicationController - def index - render :json => [ - 'admin', 'guest' - ] - end -end diff --git a/app/javascript/components/GuitarGallery.js b/app/javascript/components/GuitarGallery.js new file mode 100644 index 0000000..c7677d6 --- /dev/null +++ b/app/javascript/components/GuitarGallery.js @@ -0,0 +1,45 @@ +import React, { useEffect, useState } from 'react'; +import axios from 'axios'; +import { Title, TitleSizes, Gallery } from '@patternfly/react-core'; +import GuitarInfo from './GuitarInfo'; + +// Loading the data from the server: + +export const GuitarGallery = () => { + const getGuitars = async () => { + try { + const response = await axios.get('/guitars'); + if (response.data) { + setGuitars(response.data); + } + } catch (error) { + console.error(error); + } + }; + + const [guitars, setGuitars] = useState([]); + + useEffect(() => { + getGuitars(); + }, []); + + return ( +
Find me in app/views/guitars/index.html.erb
diff --git a/app/views/user/index.html.erb b/app/views/user/index.html.erb deleted file mode 100644 index c825aaf..0000000 --- a/app/views/user/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -Find me in app/views/user/index.html.erb
diff --git a/config/routes.rb b/config/routes.rb index 8c9f741..db1f8fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do root 'home#index' - get '/user', to: 'user#index' + get '/guitars', to: 'guitars#index' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end