Class: Admin::DocumentsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/documents_controller.rb', line 29

def create    
  @document = Document.create(params[:document])
  @document.type = params[:document][:type] || 'Document'
  @document.author = current_user
  if @document.save
    flash[:notice] = "Succesfully Saved"
    redirect_to parent_path
  else           
    render :template => admin_view_for('new')
  end    
end

#destroyObject



54
55
56
57
# File 'app/controllers/admin/documents_controller.rb', line 54

def destroy    
  @document.destroy
  redirect_to parent_path
end

#downObject



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

def down    
  @document.move_lower
  redirect_to parent_path
end

#editObject



41
42
43
# File 'app/controllers/admin/documents_controller.rb', line 41

def edit    
  render :template => admin_view_for('edit')
end

#generate_templateObject

Generate a view from template.erb



70
71
72
73
74
75
76
77
78
# File 'app/controllers/admin/documents_controller.rb', line 70

def generate_template
  if request.post?
    template = File.new("#{RAILS_ROOT}/app/views/pages/#{@document.meta_definition.label_path.gsub('/', '.')}.html.erb", 'w')
    template.write(ERB.new(IO.read("#{RAILS_ROOT}/app/views/pages/template.erb")).result(binding))
    template.close
  end
  @document.touch # delete cache (FIXME: Not ideal)
  redirect_to document_path(@document)
end

#indexObject



8
9
10
# File 'app/controllers/admin/documents_controller.rb', line 8

def index    
  @documents = Document.roots.sort_by(&:position)
end

#newObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin/documents_controller.rb', line 17

def new    
  @document.type = params[:type] || 'Document'
  if params[:parent]
    @document.parent = Document.find(params[:parent])
    @document.meta_definition = @document.parent.meta_definition.children.by_label(params[:label]).first
  else
    @document.meta_definition = MetaDefinition.find_by_label_path(params[:label_path])
  end    
  @document.label = params[:label] || @document.meta_definition.label
  render :template => admin_view_for('new')
end

#showObject



12
13
14
15
# File 'app/controllers/admin/documents_controller.rb', line 12

def show    
  render :text => "Document Not Found [#{params[:id]}]" and return unless @document
  render :template => admin_view_for('show')
end

#upObject



59
60
61
62
# File 'app/controllers/admin/documents_controller.rb', line 59

def up    
  @document.move_higher
  redirect_to parent_path
end

#updateObject



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

def update
  if @document.update_attributes(params[:document])
    flash[:notice] = "Succesfully Saved"
    redirect_to parent_path
  else
    render :template => admin_view_for('edit')
  end
end