I was working on a project that I called footy. Footy is a rails back-end, java script front project, while I was doing this project I especially learned a lot about serializer in rails , improved my java script, rails and custom css.
in the back-end, I have this drawing for project plan.I didn’t implement review and like relationship in java script , I will be doing them later on when I have more time.
So, in my project ,I implemented Match, player and Club relationships.
class Club < ApplicationRecord
has_many :matches, through: :players
class Player < ApplicationRecord
class Match < ApplicationRecord
has_many :clubs, through: :players
I also used fast Json api gem and serializers , as an example I’m am typing one of them
in player serializer file, I do this;
belongs_to :club, dependent: :destroy
belongs_to :match, dependent: :destroy
attributes :name, :number, :kind, :country, :age, :club_id, :match_id
By the way , we have dependent: :destroy , we want this in our serializer, if we don’t use it whenever we seed data using rails db:seed, in the database the table that we have for specific id will be empty, dependent: :destroy will delete this empty table and it reorganize the tables’s with new data id’s
so, it is good to use if you don’t want to see the data id with a lot numbers for example 300 or up numbers.Because we might wanna use rails db:seed more than once for testing purposes of our data.
Serialization, The process whereby an object or data structure is translated into a format suitable for transferral over a network, or storage (e.g. in an array buffer or file format).
when we use serializer, Serializer makes data available to store it.
as you can see,serializer made one more level nested data called attirubes which in this case we can access to all info about a specific player.
I have seed.rb file which I used this web site https://apifootball.com/
response = RestClient.get(url)
body = response.body
m_array = JSON.parse(body)
after converting data to json I seeded that data.
after setting up the back-end, I used vanilla js to set up front end. For html part I have 2 sections, one is where all the buttons stay other is where all the content to show users.
All the buttons have event listener with if else statements.
after using each if statement I have I make contentContainer.innerHTML =” ”
empty , when user clicks in other button , contentContainer will be filled only with that button’s event listener code.
Contribute to Yahyagok/footy--backend development by creating an account on GitHub.