Persisting Data to your website

$ rails new plane_view_api --api
class tripsController < ApplicationController
def index
trips = trip.all
render json: trips
end

def create
@trip = trip.new(trip_params)

if @trip.save
render json: @trip, status: :created, location: @trip
else
render json: @trip.errors, status: :unprocessable_entity
end
end

private

def trip_params
params.require(:trip).permit(:user, :route, :date, :local_time, :side, :pictures, :comments)
end
end
Get Data:getAllTrips() {
return fetch(URL-to-backend)
.then(res => res.json())
.then(data => {
for(let i = 0; i < data.length; i ++) {
new Trip(data[i].id, data[i].name...);
}
})
};
Send Data:fetch(URL-to-backend, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
trip: {
name: tripName
}}),
})
.then(res => {
return res.json()
})
.then(data => {
(Code to manipulate data here)
})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store