Class: Saphira::FileItemsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Saphira::FileItemsController
- Defined in:
- app/controllers/saphira/file_items_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /file_items POST /file_items.json.
-
#destroy ⇒ Object
DELETE /file_items/1 DELETE /file_items/1.json.
-
#edit ⇒ Object
GET /file_items/1/edit.
-
#index ⇒ Object
GET /file_items GET /file_items.json.
-
#new ⇒ Object
GET /file_items/new GET /file_items/new.json.
-
#show ⇒ Object
GET /file_items/1 GET /file_items/1.json.
-
#update ⇒ Object
PUT /file_items/1 PUT /file_items/1.json.
Instance Method Details
#create ⇒ Object
POST /file_items POST /file_items.json
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/saphira/file_items_controller.rb', line 59 def create @file_item = FileItem.new(params[:file_item]) respond_to do |format| if @file_item.save format.html { redirect_to @file_item, :notice => 'File item was successfully created.' } format.json { render :json => @file_item, :status => :created, :location => @file_item } else format.html { render :action => "new_#{@file_item.item_type}" } format.json { render :json => @file_item.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /file_items/1 DELETE /file_items/1.json
91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/saphira/file_items_controller.rb', line 91 def destroy @file_item = FileItem.find_by_path(params[:id]) @file_item.destroy respond_to do |format| format.html { redirect_to file_items_url } format.json { head :ok } end end |
#edit ⇒ Object
GET /file_items/1/edit
48 49 50 51 52 53 54 55 |
# File 'app/controllers/saphira/file_items_controller.rb', line 48 def edit @file_item = FileItem.find_by_path(params[:id]) respond_to do |format| format.html { render :action => "edit_#{@file_item.item_type}" } format.json { render :json => @file_item } end end |
#index ⇒ Object
GET /file_items GET /file_items.json
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/saphira/file_items_controller.rb', line 5 def index @file_item = FileItem.new(:name => 'ROOT') @file_items = FileItem.where(:parent_id => nil).all respond_to do |format| format.html # index.html.erb format.json { render :json => @file_items } end end |
#new ⇒ Object
GET /file_items/new GET /file_items/new.json
36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/saphira/file_items_controller.rb', line 36 def new @file_item = FileItem.new @file_item.item_type = params[:type] @file_item.parent_id = params[:parent_id] respond_to do |format| format.html { render :action => "new_#{@file_item.item_type}" } format.json { render :json => @file_item } end end |
#show ⇒ Object
GET /file_items/1 GET /file_items/1.json
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/saphira/file_items_controller.rb', line 17 def show @file_item = FileItem.find_by_path(params[:id]) respond_to do |format| format.html do case @file_item.item_type when Saphira::FileItem::TYPE_FOLDER @file_items = @file_item.children render :action => 'index' else render end end format.json { render :json => @file_item } end end |
#update ⇒ Object
PUT /file_items/1 PUT /file_items/1.json
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/saphira/file_items_controller.rb', line 75 def update @file_item = FileItem.find_by_path(params[:id]) respond_to do |format| if @file_item.update_attributes(params[:file_item]) format.html { redirect_to @file_item, :notice => 'File item was successfully updated.' } format.json { head :ok } else format.html { render :action => "edit_#{@file_item.item_type}" } format.json { render :json => @file_item.errors, :status => :unprocessable_entity } end end end |