Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip: No handler found for "application/javascript"
    primarykey
    data
    text
    <p>I'm trying to upload javascript files with paperclip and geting </p> <pre><code>No handler found for "application/javascript" .../paperclip-3.2.0/lib/paperclip/io_adapters/registry.rb:19:in `handler_for' .../paperclip-3.2.0/lib/paperclip/io_adapters/registry.rb:29:in `for' .../paperclip-3.2.0/lib/paperclip/attachment.rb:91:in `assign' .../paperclip-3.2.0/lib/paperclip.rb:196:in `block in has_attached_file' </code></pre> <p>I am using this as part of a templating system. As part of my seed.rb (so I'm not uploading this via a form) I loop through files in a directory, create a new Javascript object for each one, set 'path', 'extension' and 'body' and then a callback sets the paperclip attachment named 'source' before validation and another attachment named 'preview' after save. The error is occurring in <code>compile_preview</code> at <code>self.preview = file</code></p> <p>models/javascript.rb</p> <pre><code>has_attached_file :source, :default_style =&gt; :original, :path =&gt; ":rails_root/tmp/:configured_path", :url =&gt; ":configured_url", :default_url =&gt; "/assets/missing.gif", :use_timestamp =&gt; false, :storage =&gt; :filesystem before_validation :set_source before_post_process { false } after_save :compile_preview validates :body, :presence =&gt; true, :length =&gt; { :maximum =&gt; 500.kilobytes } validates :path, :presence =&gt; true validates :format, :presence =&gt; true, :inclusion =&gt; ["js"] validates :handler, :presence =&gt; true, :inclusion =&gt; ["coffee", "js"] def set_source file = StringIO.new(self.body) file.class.class_eval { attr_accessor :original_filename, :content_type } file.original_filename = "#{File.basename(self.path)}.#{self.extension}" file.content_type = "application/javascript" self.source = file end def compile_preview file = StringIO.new(self.render) file.class.class_eval { attr_accessor :original_filename, :content_type } file.original_filename = self.source_file_name file.content_type = self.source_content_type self.preview = file self.save end </code></pre> <p>I know 99% of this works because I've used it with another model, but it's just "application/javascript" which is causing a problem. I've also tried "text/plain" and the old "text/javascript" mime type too but get the same error.</p> <p>I see no mention of anyone having problems with handlers in this way before and paperclip has no mention of it.</p> <p>I'm using Rails 3.2.8 &amp; Paperclip 3.2.0</p> <p>Could my <code>handler</code> attribute be conflicting with paperclip?</p> <p>Does anyone have any insight into where I'm going wrong with this? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload