Class: Shoppy::OptionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shoppy/options_controller.rb

Direct Known Subclasses

OptionsController

Instance Method Summary collapse

Instance Method Details

#deleteObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/shoppy/options_controller.rb', line 50

def delete
  options_group = OptionsGroup.find_by(id: params[:options_group_id])
  if options_group
    options_group.destroy
    Log.newEvent("Option Groups", "Options group named '#options_group.name}' was deleted", current_admin.name)
    flash[:notice] = "Options' group has been deleted."
    redirect_to '/products/options'
  else
    page_not_found
  end
end

#editObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/shoppy/options_controller.rb', line 32

def edit
  @options_group = OptionsGroup.find_by(id: params[:options_group_id])
  if @options_group
    @options_group.name = params[:options_group][:name]
    @options_group.display = params[:options_group][:display]
    @options_group.items_string = params[:optionsItems]
    if @options_group.save
      Log.newEvent("Option Groups", "Options group named '#@options_group.name}' was updated", current_admin.name)
      flash[:notice] = "Options Group has been updated."
    else
      flash[:error] = @options_group.errors.messages
    end
    redirect_to '/products/options/' + @options_group.id.to_s
  else
    page_not_found
  end
end

#indexObject



5
6
7
# File 'app/controllers/shoppy/options_controller.rb', line 5

def index
	@options = OptionsGroup.all
end

#newObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/shoppy/options_controller.rb', line 9

def new
  if (params[:name]) && (params[:name] != "") && (params[:display]) && (params[:display] != "") && (params[:optionsItems]) && (params[:optionsItems] != "")
    if OptionsHelper::create_options_group(params[:name], params[:display], params[:optionsItems])
      Log.newEvent("Option Groups", "Options group named '#{params[:name]}' was created", current_admin.name)
      flash[:notice] = "Options Group has been created!"
    else
      flash[:warning] = "Something went wrong. Try again later"
    end
  else
    flash[:warning] = "Please make sure you have entered the options' group name, display name, and the options."
  end
  redirect_to "/products/options"
end

#showObject



23
24
25
26
27
28
29
30
# File 'app/controllers/shoppy/options_controller.rb', line 23

def show
  og = OptionsGroup.find_by(id: params[:options_group_id])
  if og
    @options_group = og
  else
    page_not_found
  end
end