I am just trying to study about Rails.
Everytime I send the get request through postman, initialize method is called, so I cannot maintain @data Array because @data is initialized at every request. Is there any way to initialize @data once, and let create, update, destroy methods work properly?
class BooksController < ApplicationController
skip_before_action :verify_authenticity_token
def initialize
super
@data = [
{ title: "Harry Potter", author: "J.K Rowling" },
{ title: "Name of the wind", author: "Patrick Rothfuss" }
]
end
def index
render json: @data
end
def create
@data.push(params[:book])
render json: @data
end
end