Class: Admin::DocumentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



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

def destroy    
  @document.destroy
  redirect_to parent_path
end

#downObject



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

def down    
  @document.move_lower
  redirect_to parent_path
end

#editObject



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

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

#generate_templateObject

Generate a view from template.erb



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

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



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

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

#newObject



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

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



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

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

#upObject



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

def up    
  @document.move_higher
  redirect_to parent_path
end

#updateObject



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

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