Class: NodesController

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

Overview

This controller exposes the REST operations required to manage the Node resource.

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#show_first_time_wizard

Instance Method Details

- (Object) create

POST /nodes



17
18
19
20
21
22
# File 'app/controllers/nodes_controller.rb', line 17

def create
  if @node.save
    flash[:notice] = 'Successfully created node.'
  end
  respond_with(@node)
end

- (Object) destroy

DELETE /nodes/<id>



46
47
48
49
# File 'app/controllers/nodes_controller.rb', line 46

def destroy
  @node.destroy
  respond_with(@node)
end

- (Object) index

GET /nodes



10
11
12
13
14
# File 'app/controllers/nodes_controller.rb', line 10

def index
  parent_id = params[:node] == 'root-node' ? nil : params[:node].to_i
  @nodes = Node.where(:parent_id => parent_id )
  respond_with(@nodes)
end

- (Object) show

GET /nodes/<id>



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

def show
  respond_with(@node)
end

- (Object) sort

POST /nodes/sort



30
31
32
33
34
35
# File 'app/controllers/nodes_controller.rb', line 30

def sort
  params[:nodes].each_with_index do |id, index|
    Node.update_all({:position => index+1}, {:id => id})
  end
  render :nothing => true
end

- (Object) update

PUT /node/<id>



38
39
40
41
42
43
# File 'app/controllers/nodes_controller.rb', line 38

def update
  if @node.update_attributes( params[:node] || ActiveSupport::JSON.decode(params[:data]) )
    flash[:notice] = 'Successfully updated node.' 
  end
  respond_with(@node)
end