Sha256: fb3d880732cfd72bbb746a682051d2ca7a05b022fbfa21ec21ea24b979cd536b

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

class ProductsController < ApplicationController
  include Applicat::Mvc::Controller::Resource
  
  load_and_authorize_resource
  
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
  
  respond_to :html, :js, :json
  
  def index
    @products = Product.all
  end
  
  def show
    @product = Product.find(params[:id])
  end
  
  def new
    @product = Product.new
  end
  
  def create
    @product = Product.new(params[:product])
    @product.user_id = current_user.id
    
    if @product.save
      redirect_to product_path(@product), notice: t('general.form.successfully_created')
    else
      render :new
    end
  end
  
  def edit
    @product = Product.find(params[:id])
  end
  
  def update
    @product = Product.find(params[:id])
    
    if @product.update_attributes(params[:product])
      redirect_to product_path(@product), notice: t('general.form.successfully_updated')
    else
      render :edit
    end
  end

  def destroy
    @product = Product.find(params[:id])
    @product.destroy
    redirect_to products_url, notice: t('general.form.destroyed')
  end
  
  def resource
    @product
  end
  
  private
  
  def not_found
    redirect_to products_path, notice: t('products.exceptions.not_found')
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
voluntary-0.7.1 app/controllers/products_controller.rb
voluntary-0.7.0 app/controllers/products_controller.rb
voluntary-0.6.0 app/controllers/products_controller.rb
voluntary-0.5.2 app/controllers/products_controller.rb
voluntary-0.5.1 app/controllers/products_controller.rb
voluntary-0.5.0 app/controllers/products_controller.rb