Class: FacetsController

Inherits:
FassetsCore::ApplicationController show all
Defined in:
app/controllers/facets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @facet = Facet.new(params[:facet])
  @facet.catalog_id = @catalog.id
  if @facet.save
    flash[:notice] = "Facet was successfully created."
    redirect_to edit_catalog_facet_path(@catalog, @facet)
  else
    if params[:facet][:caption].blank?
      flash[:error] = "Facet could not be created! Caption cannot be empty!"
    else
      flash[:error] = "Facet could not be created!"
    end      
    redirect_to :back
  end
end

#destroyObject



39
40
41
42
43
44
# File 'app/controllers/facets_controller.rb', line 39

def destroy
  @catalog = @catalog.facets.find(params[:id])
  @catalog.destroy
  flash[:notice] = "Facet was successfully destroyed."
  redirect_to catalog_path(@catalog)
end

#editObject



22
23
24
# File 'app/controllers/facets_controller.rb', line 22

def edit
  @facet = @catalog.facets.find(params[:id])
end

#newObject



5
6
# File 'app/controllers/facets_controller.rb', line 5

def new
end

#sortObject



45
46
47
48
49
50
51
# File 'app/controllers/facets_controller.rb', line 45

def sort
  @facetsInScope = Facet.where("catalog_id = ?", @catalog.id)	  
  params[:facet].each_with_index do |id, index|
    @facetsInScope.update(id, :position => index)     
  end
  render :nothing => true	  
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/facets_controller.rb', line 25

def update
  if params[:facet][:caption].blank?
    flash[:error] = "Facet could not be updated! Caption cannot be empty"
    redirect_to :back
    return
  end
  @facet = @catalog.facets.find(params[:id])
  if @facet.update_attributes(params[:facet])
    flash[:notice] = "Facet has been updated."
    redirect_to  edit_catalog_facet_path(@catalog, @facet)
  else
    render :action => 'edit'
  end
end