Sha256: 2f48630d29827f3bacc3280d9db9b608f6a36bc93c4cfd7f4ab5352e662ef8fa

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

class Admin::OptionGroupsController < Admin::BaseController

  def new
    #note: its the option id being passed even though we're in the option group controller 
    @option = Option.find(params[:id])
    #messy SQL but there doesn't seem to be an easier way (at least that i know of)
    @all_option_values = OptionValue.find_by_sql(["SELECT * FROM option_values WHERE id NOT IN (SELECT option_value_id FROM option_groups WHERE option_id = ? ORDER BY name)", 
                                                 @option.id])
  end
  
  def create
    @option = Option.find(params[:id])
    @option_value = OptionValue.find(params[:option_value])
    option_group = OptionGroup.new
    option_group.option = @option
    option_group.option_value = @option_value
    option_group.save!
    flash[:notice] = 'Option group was successfully created.'
    redirect_to :controller => 'options', :action => 'edit', :id => @option    
  rescue Exception => e
    logger.error("unable to create/update option group")
    logger.error("message: " + e.message)
    flash[:error] = ' Problem saving option group'
    render :action => 'new'
  end

  def destroy
    group = OptionGroup.find(params[:id])
    option = group.option
    group.destroy
    #OptionGroup.destroy(params[:id])
    flash[:notice] = 'Option group successfully deleted'
    redirect_to :controller => 'options', :action => 'edit', :id => option
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
railscart-0.0.1 starter-app/vendor/plugins/railscart/app/controllers/admin/option_groups_controller.rb
railscart-0.0.2 starter_app/vendor/plugins/railscart/app/controllers/admin/option_groups_controller.rb