module-and-template-store/app/controllers/extensions_controller.rb

76 lines
2.0 KiB
Ruby

class ExtensionsController < ApplicationController
before_action :set_extension, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, only: [:new, :edit, :create, :update, :destroy]
# GET /extensions
# GET /extensions.json
def index
@extensions = Extension.all
end
# GET /extensions/1
# GET /extensions/1.json
def show
end
# GET /extensions/new
def new
@extension = Extension.new
end
# GET /extensions/1/edit
def edit
end
# POST /extensions
# POST /extensions.json
def create
@extension = Extension.new(extension_params)
respond_to do |format|
if @extension.save
format.html { redirect_to @extension, notice: 'Extension was successfully created.' }
format.json { render action: 'show', status: :created, location: @extension }
else
format.html { render action: 'new' }
format.json { render json: @extension.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /extensions/1
# PATCH/PUT /extensions/1.json
def update
respond_to do |format|
if @extension.update(extension_params)
format.html { redirect_to @extension, notice: 'Extension was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @extension.errors, status: :unprocessable_entity }
end
end
end
# DELETE /extensions/1
# DELETE /extensions/1.json
def destroy
@extension.destroy
respond_to do |format|
format.html { redirect_to extensions_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_extension
@extension = Extension.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def extension_params
params.require(:extension).permit(:title, :author, :description, :preview, :preview_cache, :extension, :extension_cache)
end
end