add image from folder outside of the project - ruby-on-rails

I need to show some images that are outside of the project folder of rails, is it possible that rails can take them? or must they necessarily be inside the assets folder?

Upload image to cloud and use HTTP path.
If you let image outside the folder of rails, you will have some trouble about asset-pipeline.

Related

Download image from database to project folder with Paperclip

I want to download an image stored in database with paperclip and put it in my project folder. In app/assets/images for example.
Why? : Because I want to put image in a Word. So when I use docx_replace or caracal gem I cant put directly image within the variable from database (that don't work). But I can put image directly from folder. So I want to put the image from DB to folder, put in the Word and delete it after insertion. That's why. But if you have another technique tell me.
Do you now a way in order to do that ?
As you store your files locally and paperclip provides helpers to the full path of the file, you can just use Ruby FileUtils to copy the file to the public directory in your action. You don't need to download it, because it is already in the filesystem.
This answer provides some base code for this: https://stackoverflow.com/a/5776577/1023609

Rails - how do you edit files included by a gem in the asset pipeline?

I am new to rails so this is probably a simple question about using the asset pipeline.
In my app, I want to use this jquery plugin: http://www.fyneworks.com/jquery/star-rating/
So to do it, I included the following gem in my gemfile: https://github.com/RichGuk/jquery-star-rating-rails
However, I find that the image used for the star ratings is too low resolution and I'd also like to change the style. However, all 3 versions of the stars that are displayed are held in one image so I'd have to play around with the scripts as well to make sure they are configured properly if I make the image for the stars larger.
Back to my question: How do I edit this image file in my application?
I've tried downloading all the files and putting them in my vender directory and editing the file but it did not seem to work.
I know the files are included by the gem but how do make the files visible to edit?
Appreciate the help!
So the asset pipeline consists of potentially many directories (assuming you are using gems that inject their own assets into the pipeline). When an asset is being grabbed in Rails, Rails goes through these directories (in the same order, every time) to find the asset. When the name of the file is first found, that's it, Rails grabs it and uses that file.
Vendor asset directories are specified after app assets, I believe. So, if you place the image that you want to change in the app/assets/images folder, you'll essentially be overriding that vendor image in your application with your own image since Rails will search it's own app/assets first. Obviously, the files need to be named the same.
Try adding your star image in your assets path. It seem to
reference star.gif using the asset_path
I would also try
overriding the star plugin by creating your own css file.

Rails - Change Image Directory?

I've developed a simple app to display images in a series of subdirectories based on querystring input. (I more or less built my own Rails version of 360Works SuperContainer, for FileMaker.) I have copied a few test directories into public/images and everything seems to be working just great, but this app needs to operate over upwards of 60gb of images, and putting them all into the public/images folder isn't going to really be feasible.
Other than hard-coding the path into my model, how can I set a configuration option to specify a different default directory for the images folder?
I think you can change the asset_host field :
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#M001688

Put files (css, html, js, images) per feature in one place in Rails 3?

Whenever I add a new feature (eg. something I downloaded) I tend to want to put all the files (css, html, js, images) in one place.
Symfony 2.0 will have this new feature they called bundle system. Everything will be in its own folder. This will be great for adding new features so you don't have to mix all css, js, image files with each other. It should be per feature instead.
And also it would be great for deleting features. Then you know that all files are in one place and don't have to look for them throughout your application.
Eg.
Instead of this...
images/
fader.img
cart1.img
cart2.img
javascripts/
fader.js
cart.js
stylesheets/
fader.css
cart_main.css
cart_sub.css
...you should have it like this...
venture/
fader/
fader.img
fader.css
fader.js
cart/
cart1.img
cart2.img
cart.js
cart_main.css
cart_sub.css
Is there a way of doing so in Rails 3?
Sure, you could just treat them like a plugin - making a set of files into a plugin is very simple, after all - you basically just put them in a folder, in a file structure parallel to the root of your rails app, then put that folder in your vendor/plugins folder.
Here's the guide on it: http://guides.rubyonrails.org/plugins.html
Then, if you want to delete a feature, just destroy it's plugin folder, and you're clean.

Directory to store cached files in Rails?

I am generating some large files in my Rails application. Fortunately, they only need to be generated once. I would like to save these files to disk so that I don't have to generate them again.
Which directory in my Rails application is the most appropriate place to put application generated files?
Thanks!
If security of the files is not an issue you can put them in a subdirectory of public (for example, public/assets) which in your deploy script is symlinked to a directory in shared/public so that when you redeploy the files are retained.
If security is an issue, the solution is similar, though you would not want the directory to be web accessible. Instead you would use a controller to control access and serve up the files with send_file.

Resources