Sha256: bd507902b4dbd7325b19eae8bf069add49c91249bfbe3e05d45ecea40edc7d20

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 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, 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, 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

15 entries across 15 versions & 1 rubygems

Version Path
voluntary-0.4.0 app/controllers/products_controller.rb
voluntary-0.3.0 app/controllers/products_controller.rb
voluntary-0.2.4 app/controllers/products_controller.rb
voluntary-0.2.3 app/controllers/products_controller.rb
voluntary-0.2.2 app/controllers/products_controller.rb
voluntary-0.2.1 app/controllers/products_controller.rb
voluntary-0.2.0 app/controllers/products_controller.rb
voluntary-0.1.0 app/controllers/products_controller.rb
voluntary-0.1.0.rc4 app/controllers/products_controller.rb
voluntary-0.1.0.rc3 app/controllers/products_controller.rb
voluntary-0.1.0.rc2 app/controllers/products_controller.rb
voluntary-0.1.0.rc1 app/controllers/products_controller.rb
voluntary-0.0.3 app/controllers/products_controller.rb
voluntary-0.0.2 app/controllers/products_controller.rb
voluntary-0.0.1 app/controllers/products_controller.rb