app/controllers/locations_controller.rb
class LocationsController < ApplicationController
before_action :set_location, only: %i[ show edit update destroy ]
# GET /locations or /locations.json
def index
@locations = Location.all
end
# GET /locations/1 or /locations/1.json
def show
@stories = @location.stories
end
# POST /locations or /locations.json
def create
@location = Location.new(location_params)
respond_to do |format|
if @location.save
format.html { redirect_to location_url(@location), notice: t(".created") }
format.json { render :show, status: :created, location: @location }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @location.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /locations/1 or /locations/1.json
def update
update_record(@location, location_params, location_url(@location))
end
# DELETE /locations/1 or /locations/1.json
def destroy
@location.destroy!
respond_to do |format|
format.html { redirect_to locations_url, notice: t(".destroyed") }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_location
@location = Location.find(params[:id])
end
# Only allow a list of trusted parameters through.
def location_params
params.require(:location).permit(:address)
end
end