Class: Admin::TaxonsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/taxons_controller.rb

Instance Method Summary collapse

Instance Method Details

#childrenObject

Action for getting the children of a taxon right now it only responds to json requests



72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/admin/taxons_controller.rb', line 72

def children
  @taxon = Taxon.find params[:id]
  @children = @taxon.children
  @tree = tree_children(@taxon)
  respond_to do |format|
    format.html
    format.json { render :json => @tree }
  end
  
end

#createObject



29
30
31
32
33
34
35
36
# File 'app/controllers/admin/taxons_controller.rb', line 29

def create
  @taxon = Taxon.new(params[:taxon])
  if @taxon.save
    redirect_to edit_admin_taxonomy_url(@taxon.taxonomy), :notice => "Successfully created taxon."
  else
    render :action => 'new'
  end
end

#destroyObject



63
64
65
66
67
# File 'app/controllers/admin/taxons_controller.rb', line 63

def destroy
  @taxon = Taxon.find(params[:id])
  @taxon.destroy
  redirect_to edit_admin_taxonomy_url(@taxon.taxonomy), :notice => "Successfully destroyed taxon."
end

#editObject



38
39
40
41
# File 'app/controllers/admin/taxons_controller.rb', line 38

def edit
  @taxon = Taxon.find(params[:id])
  @taxonomy = @taxon.taxonomy
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/admin/taxons_controller.rb', line 5

def index

  if @taxonomy
    @taxons = @taxonomy.children.order(:pos)
  else
    @taxons = Taxon.all
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json  { render :json => @taxons}
  end
  
  
end

#newObject



25
26
27
# File 'app/controllers/admin/taxons_controller.rb', line 25

def new
  @taxon = Taxon.new
end

#showObject



21
22
23
# File 'app/controllers/admin/taxons_controller.rb', line 21

def show
  @taxon = Taxon.find(params[:id])
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/admin/taxons_controller.rb', line 43

def update
  @taxon = Taxon.find(params[:id])
  if @taxon.update_attributes(params[:taxon])

    # Move the taxon to the correct position
    if params[:left_of_id] != params[:parent_id]
      @right_taxon = Taxon.find(params[:left_of_id])
      @taxon.move_to_left_of(@right_taxon) if @right_taxon && @taxon.siblings.include?(@right_taxon)
    end

    if params[:format] == :json
      render :json => "ok"
    else
      redirect_to edit_admin_taxonomy_url(@taxon.taxonomy), :notice  => "Successfully updated taxon."
    end
  else
    render :action => 'edit'
  end
end