rails + attachment_fu: issue with files in directories - ruby-on-rails

I use attachment_fu for my rails app. It's great for me.
However, the designer who works with me complains about it because it saves files in different directory. She said that she can't handle those files efficiently with Photoshop as they are scattered.
I tried to persuade her with the following reasons.
We can avoid file name clash
It's faster than when they are in the same directory
But I couldn't convince her. How would you? Or are you with her? If so, why?
Sam

I think Adobe Photoshop has a built-in utility called 'Bridge' which allows easy asset management, might be worth having a look.

Related

True Paperclip Replacement (Speficially Structure of the File System)

With Rails 6, I need to replace Paperclip, but I can't find any substitutions that actually easily replicate it.
Specifically, the file structure paperclip used:
:model/:attachmant_field/000/000/000/:identifier/:style/:original_file_name
Over the last decade we have built several tools that rely on that structure (or something similar) and in addition our users expect that after uploading an image, they can reference the styles with the same file name and a permanent url (not a randomly generated name like ActiveStorage and Shrine does) and change the "style" component in the url to a different one in their html.
I've spent several days both on Shrine and ActiveStorage working to get the file structure and naming to work on and keep failing, as despite being "natural replacements" they don't actually handle things in the same way.
Our end system is on Amazon S3, though integrating with that hasn't been the issue, just the file system.
Thanks for your help, it's been really frustrating having to remove something that works great when there seems to be nothing that actually replaces it, if you want/need things done in the same way. I'd rather not have to start rewriting all of tools that we developed and resetting our customers expectations to work with a new structure.
Thanks so much.
Have you tried Carrierwave? You can specify any storage path and build it dynamically using model name (model.class.to_s.underscore), attachment field (mounted_as), model id (model.id). The original file name is also available as original_filename.

Why is my rails app generating .js.js files in the application structure?

I've got this angular/rails app going, I had been previously been playing around with vim-coffee plugins to watch my files and compile, I was using it to debug. Now, I feel like there is some residual behavior that is compiling the coffee files into .js.js files right in same folder. I'm not enjoying this behavior, though it isn't impacting the app itself. What should I be doing to address this? Actually, looking at this further, this is happening across all my coffee files in this application, as far as I can tell, it isn't happening in other projects.
This has nothing to do with vim or rails in particular; it's just that the CoffeeScript compiler will only look at the file extension (.coffee). Any other part of the file is preserved. So you have x.js.coffee and it gets compiled to x.js.js because .coffee -> .js. This could be anything like x.foo.bar.coffee would become x.foo.bar.js by nature of the compiler.
As you said this has no effect on the app itself, so I would just ignore it. The generated files shouldn't even be tracked as part of your project.
yeah, so apparently I had put
autocmd BufWritePost *.coffee silent make!
into my ~/.vimrc and that was autocompiling coffee files, all I had to do was comment it out. so not really a vim issue, more of a user settings configuration question but thank you all for the input and effort.

sprockets duplicate file naming

I have the following files, in my asset path:
javascripts/abc.js
templates/abc.js.mustache # this gets compiled to abc.js
naturally, they both would be requested as assets/abc.js.
Is there a fix? If not, what part of the Sprockets source would need to be modified?
My thinking is along the lines that if the engine can remove the extension, it can well enough add a suffix.
It may be too obvious, but isn't it better just rename files? I understand nature of your question, but it's hard to imagine ultimate requirements, which forces same filenames for those files. Hence this, you have foobar.js and foobar.js.mustache, which compiles to foobar.js. Why they have same names? They do same things? This is design flaw, if you ask me.
I have the same problem, and have not yet found a satisfying solution. My sites have many complex full-stack plugins (aka engines), and they have lots of css, js, and image files. Having to namespace, eg "styles.css" in each plugin kinda sucks. When upgrading to Rails 3, I assumed the file resolver would put engines/plugins in /styles, but no, they all get combined into one virtual path.
My current temporary solution is to build a rake task that I run that checks for duplicate filenames. I run it before committing code and on deployment. Hackity! If that helps, great, if not, perhaps someone out there has a more elegant solution...

uploading a file with rail - what is the best approach

I have a requirement of uploading a file to my disk through my webpage. Seems like I have two options
My requirement is specific that I will upload ONLY text files.
Using default rails methods to upload a file.
Ex: http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
Using a plugin like 'PaperClip'
Following are my concerns:
I want to keep the file upload as simple as possible
Keep as away as dependencies like Imagemagic etc
I'm using rails 2.8.3
concurrent file uploads can be happen by multiple users
please can someone tell me what are the pros and cons of having
writing a simple file upload (option 1)
using a plugin/gem to upload a files
Writing your own file uploader is an option, but using a pre-built gem provides you with all of the code you need, straight after install.
Gems will usually have all of the functionality packaged into them that handles all of the cross-platform issues and security headaches your likely to run into by writing something from scratch. A well maintained gem will also have a good community behind it, keeping things up to date.
The popular Gems out there are really easy to use, and unless you are resizing images etc, you shouldn't need ImageMagick installed. Have a look at these:
http://railscasts.com/episodes/134-paperclip
https://github.com/technoweenie/attachment_fu/wiki
Paperclip is far easier to build a simple upload form with, but I'm not sure if it works on Rails 2. Attachment_fu is an old favorite from the Rails 2 days and will definitely be able to handle your problem, it just requires a little more configuration.

WYSIWYG image uploads in Rails App

Can anyone recommend a way of creating a view where users can upload images to my app through a WYSIWYG editor?
I've tried solving this using CK Editor and Paperclip but am having lots of trouble... Maybe I'm going about this the wrong way.
If someone's done this before I'd really like to know how! I don't have a editor or file storage mechanism preference so fire away...
This is all dependent on the WYSIWYG's file upload API. From there, just build an ImagesController to handle requests from that API, use whatever system (Paperclip is good) to handle those files internally, and you should be good to go. You won't find a plug-and-play solution; you'll have to hand-roll it.
Turns out that, with more targeted Google searching, you can find a preexisting solution. Here's one for TinyMCE and Rails. You may, however, end up finding that it doesn't meet your needs, in which case I would not be surprised to find that creating your own solution would be simpler than you expect :)
You could try Bootsy. It's a WYSIWYG editor with image upload capability. Includes a (rather simple) image manager as well.
https://github.com/volmer/bootsy
There is an other solution for rails out there:
https://github.com/spohlenz/tinymce-rails
You can load it as gem and configure it via a yml file. And it comes with an extra language gem.

Resources