Class: Admin::DocumentsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::DocumentsController
- Defined in:
- app/controllers/admin/documents_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #down ⇒ Object
- #edit ⇒ Object
-
#generate_template ⇒ Object
Generate a view from template.erb.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #up ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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. = current_user if @document.save flash[:notice] = "Succesfully Saved" redirect_to parent_path else render :template => admin_view_for('new') end end |
#destroy ⇒ Object
53 54 55 56 |
# File 'app/controllers/admin/documents_controller.rb', line 53 def destroy @document.destroy redirect_to parent_path end |
#down ⇒ Object
63 64 65 66 |
# File 'app/controllers/admin/documents_controller.rb', line 63 def down @document.move_lower redirect_to parent_path end |
#edit ⇒ Object
40 41 42 |
# File 'app/controllers/admin/documents_controller.rb', line 40 def edit render :template => admin_view_for('edit') end |
#generate_template ⇒ Object
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..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 |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/admin/documents_controller.rb', line 7 def index @documents = Document.roots.sort_by(&:position) end |
#new ⇒ Object
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. = @document.parent..children.by_label(params[:label]).first else @document. = MetaDefinition.find_by_label_path(params[:label_path]) end @document.label = params[:label] || @document..label render :template => admin_view_for('new') end |
#show ⇒ Object
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 |
#up ⇒ Object
58 59 60 61 |
# File 'app/controllers/admin/documents_controller.rb', line 58 def up @document.move_higher redirect_to parent_path end |
#update ⇒ Object
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 |