Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paperclip_private

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paperclip_private

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

+--- + +Private Attachments +------------------- +If you want to place files behind a controller in order to perform validation you can. + +In your routes.rb file mount the paperclip engine with any path you'd like. +Ex: +ruby +mount PaperclipPrivate::Engine => 'paperclip/' + + +You have to register class names and their attachments with the whitelist registry. This can happen in the controller or in config/paperclip_private.rb +The following example would whitelist the class PrivateAttachment's file: +ruby +require 'paperclip_private' +PaperclipPrivate::Whitelist.register({PrivateAttachment: :file}) + +You can also pass an array of names like {PrivateAttachment: [:file, :avatar]}. + +Then in your model add privacy: :private to the has_attached_file options. This can also accept a lambda that gets passed the attachment instance and expects back either :private or :public. +Then add the method can_download_attachment?. +The method can_download_attachment? gets passed the controller instance and the params and is expected to return true, false, or raise Paperclip::Errors::AccessDeniedError. +The controller is passed so that methods like current_user can be run on it to get the user instance for validation puprposes. Duplicated params gets passed to do things like allow anyone if the style is :thumb or to only allow :original to paid users. +Ex: +```ruby

  • has_attached_file :file, privacy: :private
  • def can_download_attachment?(controller, params)
  • params[:style] == :thumb || (!controller.current_user.nil? && created_by == controller.current_user.id)
  • end +```

FAQs

Package last updated on 22 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc