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
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. = current_user if @document.save flash[:notice] = "Succesfully Saved" redirect_to parent_path else render :template => admin_view_for('new') end end |
#destroy ⇒ Object
54 55 56 57 |
# File 'app/controllers/admin/documents_controller.rb', line 54 def destroy @document.destroy redirect_to parent_path end |
#down ⇒ Object
64 65 66 67 |
# File 'app/controllers/admin/documents_controller.rb', line 64 def down @document.move_lower redirect_to parent_path end |
#edit ⇒ Object
41 42 43 |
# File 'app/controllers/admin/documents_controller.rb', line 41 def edit render :template => admin_view_for('edit') end |
#generate_template ⇒ Object
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..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
8 9 10 |
# File 'app/controllers/admin/documents_controller.rb', line 8 def index @documents = Document.roots.sort_by(&:position) end |
#new ⇒ Object
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. = @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
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 |
#up ⇒ Object
59 60 61 62 |
# File 'app/controllers/admin/documents_controller.rb', line 59 def up @document.move_higher redirect_to parent_path end |
#update ⇒ Object
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 |