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 @categories = Extension.get_categories @sort_type = Extension::SORT_TYPE render layout: "product_index" end # GET /extensions/1 # GET /extensions/1.json def show @extensions = Extension.all render layout: "extension_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 @extension.get_version_number 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) @extension.get_version_number 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, :extension, :extension_cache,:thumbnail, :thumbnail_cache, :key, :repository, :git_url, :price, :tag, previews_attributes: ['id', 'image', 'image_cache', '_destroy']) end end