rendered paste body def list
@type = @current_product.archetype
@features = @type.features
end
def create
@characteristic = Characteristic.new(params[:characteristic])
if @characteristic.save
flash[:notice] = 'Characteristic was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@feature = Feature.find(params[:feature_id])
@characteristic = @feature.characteristics.find(:all, :conditions => ['product_id = ?', @current_product.id])
if @characteristic.length == 1
@characteristic = @characteristic.first
else
@characteristic = Characteristic.new
end
end
def update
@feature = Feature.find(params[:feature_id])
@characteristic = @feature.characteristics.find(:all, :conditions => ['product_id = ?', @current_product.id])
# If it doesn't exist already
if @characteristic.length == 0
@edit = Characteristic.new(params[:characteristic])
@feature.characteristics << @edit
@current_product.characteristics << @edit
# If it does exist, and it's not a list
elsif @characteristic.length == 1
@edit = @characteristic.first
@edit.value = params[:characteristic][:value]
end
if @edit.save
flash[:notice] = 'Characteristic updated'
redirect_to :action => 'list'
else
flash[:notice] = 'There were problems updating the characteristic'
render :action => 'edit'
end
end