diff options
Diffstat (limited to 'app/controllers/organisations_controller.rb')
-rw-r--r-- | app/controllers/organisations_controller.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb new file mode 100644 index 0000000..dbff777 --- /dev/null +++ b/app/controllers/organisations_controller.rb @@ -0,0 +1,70 @@ +class OrganisationsController < ApplicationController + before_action :set_organisation, only: %i[ show edit update destroy ] + + # GET /organisations or /organisations.json + def index + @organisations = Organisation.all + end + + # GET /organisations/1 or /organisations/1.json + def show + end + + # GET /organisations/new + def new + @organisation = Organisation.new + end + + # GET /organisations/1/edit + def edit + end + + # POST /organisations or /organisations.json + def create + @organisation = Organisation.new(organisation_params) + + respond_to do |format| + if @organisation.save + format.html { redirect_to organisation_url(@organisation), notice: "Organisation was successfully created." } + format.json { render :show, status: :created, location: @organisation } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @organisation.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /organisations/1 or /organisations/1.json + def update + respond_to do |format| + if @organisation.update(organisation_params) + format.html { redirect_to organisation_url(@organisation), notice: "Organisation was successfully updated." } + format.json { render :show, status: :ok, location: @organisation } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @organisation.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /organisations/1 or /organisations/1.json + def destroy + @organisation.destroy! + + respond_to do |format| + format.html { redirect_to organisations_url, notice: "Organisation was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_organisation + @organisation = Organisation.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def organisation_params + params.require(:organisation).permit(:name) + end +end |