Sha256: c3c83c354a1ccd0247fea56d0b3306ef4c0495153b403d120d9de720d989bd68

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

class LocationsController < ApplicationController

  def index
    @locations = Location.all
  end

  def new
    build_location_form
  end

  def create
    build_location_form
    options = { flash: { success: "You've successfully created a location." } }
    save_location_form(options) or render "new"
  end

  def show
    load_location_form
  end

  def update
    load_location_form
    build_location_form
    options = { flash: { success: "You've successfully updated location." } }
    save_location_form(options) or render "show"
  end

  def destroy
    @location ||= Location.find(params[:id])
    @location.destroy
    redirect_to locations_path, flash: { success: "You've successfully deleted this location." }
  end

  private
  def location_params
    params.require(:location).permit!
  end

  def build_location_form
    @location ||= LocationForm.new(Location.new)
  end

  def load_location_form
    @location ||= LocationForm.new(Location.find(params[:id]))
  end

  def save_location_form(options)
    if @location.validate(params[:location])
      @location.save
      redirect_to locations_path, options
    end
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
country_state_select-3.0.3 test/dummy/app/controllers/locations_controller.rb
country_state_select-3.0.2 test/dummy/app/controllers/locations_controller.rb
country_state_select-3.0.1 test/dummy/app/controllers/locations_controller.rb
country_state_select-3.0.0 test/dummy/app/controllers/locations_controller.rb