2011-04-11 09:35:08 +01:00
|
|
|
class ProductsController < ApplicationController
|
2011-11-11 17:13:09 +00:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :find_product, :only => [:show, :edit, :update, :destroy]
|
|
|
|
before_filter :find_platform
|
2011-12-05 09:29:17 +00:00
|
|
|
before_filter :build_product_stub, :only => [:new, :create]
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2011-11-24 21:46:19 +00:00
|
|
|
load_and_authorize_resource :platform
|
|
|
|
load_and_authorize_resource :product, :through => :platform
|
2011-04-11 09:35:08 +01:00
|
|
|
|
2011-04-11 17:55:52 +01:00
|
|
|
def new
|
|
|
|
@product = @platform.products.new
|
|
|
|
@product.ks = DEFAULT_KS
|
|
|
|
@product.menu = DEFAULT_MENU
|
|
|
|
@product.counter = DEFAULT_COUNTER
|
2011-11-11 19:11:27 +00:00
|
|
|
@product.build_script = DEFAULT_BUILD
|
2011-04-11 17:55:52 +01:00
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
# def clone
|
|
|
|
# @template = @platform.products.find(params[:id])
|
|
|
|
# @product = @platform.products.new
|
|
|
|
# @product.clone_from!(@template)
|
|
|
|
#
|
|
|
|
# render :template => "products/new"
|
|
|
|
# end
|
2011-04-15 10:23:12 +01:00
|
|
|
|
2011-04-14 08:23:08 +01:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2011-04-11 17:55:52 +01:00
|
|
|
def create
|
|
|
|
@product = @platform.products.new params[:product]
|
|
|
|
if @product.save
|
2011-04-14 08:23:08 +01:00
|
|
|
flash[:notice] = t('flash.product.saved')
|
2011-04-11 17:55:52 +01:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2011-04-14 08:23:08 +01:00
|
|
|
flash[:error] = t('flash.product.save_error')
|
2011-04-11 17:55:52 +01:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
2011-04-11 09:35:08 +01:00
|
|
|
|
2011-04-14 20:43:42 +01:00
|
|
|
def update
|
|
|
|
if @product.update_attributes(params[:product])
|
|
|
|
flash[:notice] = t('flash.product.saved')
|
|
|
|
redirect_to @platform
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.product.save_error')
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-14 08:23:08 +01:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2011-04-28 11:23:52 +01:00
|
|
|
def destroy
|
|
|
|
@product.destroy
|
|
|
|
flash[:notice] = t("flash.product.destroyed")
|
|
|
|
redirect_to @platform
|
|
|
|
end
|
|
|
|
|
2011-04-11 09:35:08 +01:00
|
|
|
protected
|
|
|
|
|
2011-04-14 20:43:42 +01:00
|
|
|
def find_product
|
|
|
|
@product = Product.find params[:id]
|
|
|
|
end
|
|
|
|
|
2011-04-11 17:55:52 +01:00
|
|
|
def find_platform
|
|
|
|
@platform = Platform.find params[:platform_id]
|
|
|
|
end
|
2011-12-05 09:29:17 +00:00
|
|
|
|
|
|
|
def build_product_stub
|
|
|
|
@product = Product.new(:platform_id => params[:platform_id])
|
|
|
|
end
|
2011-04-11 09:35:08 +01:00
|
|
|
end
|