Class: AttachmentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AttachmentsController
- Defined in:
- app/controllers/attachments_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#description ⇒ Object
This returns a json object with description information of the requested file.
- #destroy ⇒ Object
-
#download ⇒ Object
This action allows to download a file, which is not in the public/ directory but at a secured location.
- #index ⇒ Object
-
#update ⇒ Object
PUT /attachments/1 PUT /attachments/1.json.
Methods inherited from ApplicationController
#current_navable, #current_navable=, #current_user, #point_navigation_to, #redirect_www_subdomain, #set_locale
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/attachments_controller.rb', line 10 def create if secure_parent :create_attachment_for, secure_parent secure_parent.touch else :create, Attachment end @attachment = Attachment.create! author: current_user @attachment.update_attributes(params[:attachment]) end |
#description ⇒ Object
This returns a json object with description information of the requested file.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/attachments_controller.rb', line 64 def description @attachment = Attachment.find(params[:attachment_id]) :read, @attachment respond_to do |format| format.json do self.formats = [:html, :json] render json: { title: @attachment.title, description: @attachment.description, author: @attachment..title, html: render_to_string(partial: 'attachments/description', formats: [:html], locals: {attachment: @attachment}) } end end end |
#destroy ⇒ Object
38 39 40 41 |
# File 'app/controllers/attachments_controller.rb', line 38 def destroy @attachment = Attachment.find(params[:id]) @attachment.destroy end |
#download ⇒ Object
This action allows to download a file, which is not in the public/ directory but at a secured location. That way, access control for uploaded files cannot be circumvented by downloading files directly from the public folder.
github.com/carrierwaveuploader/carrierwave/wiki/How-To%3A-Secure-Upload
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/attachments_controller.rb', line 49 def download path = "" if secure_version if @attachment.file.versions[secure_version] path = @attachment.file.versions[secure_version].current_path end else path = @attachment.file.current_path end send_file path, x_sendfile: true, disposition: :inline end |
#index ⇒ Object
7 8 |
# File 'app/controllers/attachments_controller.rb', line 7 def index end |
#update ⇒ Object
PUT /attachments/1 PUT /attachments/1.json
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/attachments_controller.rb', line 24 def update @attachment = Attachment.find(params[:id]) respond_to do |format| if @attachment.update_attributes(params[:attachment]) format.html { redirect_to @attachment, notice: 'Attachment was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @attachment.errors, status: :unprocessable_entity } end end end |