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

82 lines
2.2 KiB
Ruby
Raw Permalink Normal View History

2013-12-25 10:39:05 +00:00
class TemplatesController < ApplicationController
before_action :set_template, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, only: [:new, :edit, :create, :update, :destroy]
2013-12-25 10:39:05 +00:00
2014-03-14 06:37:59 +00:00
2013-12-25 10:39:05 +00:00
# GET /templates
# GET /templates.json
def index
@templates = Template.all
2014-03-14 06:37:59 +00:00
@categories = Extension.get_categories
@sort_type = Extension::SORT_TYPE
render layout: "product_index"
2013-12-25 10:39:05 +00:00
end
# GET /templates/1
# GET /templates/1.json
def show
2014-03-14 06:37:59 +00:00
@templates = Template.all
render layout: "template_show"
2013-12-25 10:39:05 +00:00
end
# GET /templates/new
def new
@template = Template.new
end
# GET /templates/1/edit
def edit
end
# POST /templates
# POST /templates.json
def create
@template = Template.new(template_params)
respond_to do |format|
if @template.save
format.html { redirect_to @template, notice: 'Template was successfully created.' }
format.json { render action: 'show', status: :created, location: @template }
else
format.html { render action: 'new' }
format.json { render json: @template.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /templates/1
# PATCH/PUT /templates/1.json
def update
respond_to do |format|
if @template.update(template_params)
format.html { redirect_to @template, notice: 'Template was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @template.errors, status: :unprocessable_entity }
end
end
end
# DELETE /templates/1
# DELETE /templates/1.json
def destroy
@template.destroy
respond_to do |format|
format.html { redirect_to templates_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_template
@template = Template.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def template_params
2014-06-30 10:26:12 +00:00
params.require(:template).permit(:title, :author,:thumbnail, :thumbnail_cache, :template, :template_cache, previews_attributes: ['id', 'image', 'image_cache', '_destroy'])
2013-12-25 10:39:05 +00:00
end
end