Displaying image in rails from a different folder - ruby-on-rails

How could I display an image from a folder other than images folder under the app/assets?
Suppose I have another folder called im under assests. i.e app/assets/im and I need to display an image under the im folder with the name same as an image under the images folder, how could I do it?

If you are using Asset Pipeline, all folders (not in the pre-compilation path) will be copied to the public/assets folder.
To access the asset, simply do asset_url("im/image_name.png"). This will fetch your image.

Related

How to save images inside assets folder at runtime in grails 3 app?

In my grails app i need to upload and image and render the same image in my view.
I could upload the image files only inside src/main/webapp directory by following code :
def webrootDir = servletContext.getRealPath("/") //app directory
String imageDestination = webrootDir + params.id;
if(image){
File uploadedImage = new File(webrootDir,"${params.id}");
println "uploadedImage = ${uploadedImage.getAbsoluteFile()}"
if(uploadedImage?.exists()){
uploadedImage.delete()
}
image.transferTo(uploadedImage);}
But i couldn't render the image from this location in <img> tag.
Is there any way to put files inside assets directory while uploading, or is there any way to render from src/main/webapp directory?
Please help.
I would upload and serve these images from somewhere outside of your app. For example, upload the images to S3 (or similar) and make them publicly accessible so that you can still refer to them within your app. Either keep track of the image URLs in a database or use a convention that will allow you to build the image URLs within your app.
You could also use a directory on your server to store the images and then make them publicly accessible somehow. You could serve them via Tomcat using a different context or use Apache to direct requests either to your app or to serve images directly.
Hope that makes sense.

Download image from database to project folder (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.
Do you now a way in order to do that ?

How can I get all image names in asset catalog group?

In my app I had a folder of images from which I was getting the names to use as keys to a Dictionary. I have now moved all images to an asset catalog and created groups for the relevant folders. The code using FileManager is not working anymore as it can not find any folders (due to the assets being compiled into a .car file).
How should I approach this?
So (following matt's suggestion) here is what I did:
I created a RunScript build phase to run before compiling
and used a script to create a txt file with the names of the files that I can then use during runtime
#!/bin/sh
>./your_app_folder/fileNames.txt
for FILE in ./your_app_folder/Images.xcassets/actions/*; do
echo $FILE >> ./your_app_folder/fileNames.txt
done
You have two choices:
Don't Do That. Go right on using a folder of images.
Supply the keys in some other way. If you don't want to hard-code them into the code itself, you could make a text file. But of course you will have to keep that text file updated as you add / remove images.
You'll notice that I didn't say you could magically introspect the asset catalog. That's because you can't.

Location of the splash image when using trigger io

I am trying to figure out the location where I should be adding my custom splash image. I followed the instructions at, http://docs.trigger.io/en/v1.4/modules/launchimage.html#modules-launchimage however I don't know the folder location to place this image within my trigger project src structure.
You can place the image anywhere in the src folder, the path you give is relative to src.
For example, if you have a file your-app/src/splash.png then putting "splash.png" in config.json should work.
If you use the App config page in the Toolkit to select the image it will let you choose from the files in src so you don't have to manually enter the path.

How to bundle non-version controlled images in Xcode's Resources folder?

Here are the approaches we tried but did not work
Version control the images - bloats up our git repo, not a good idea
Images on DropBox - Whenever our designer adds an image on Dropbox it gets available to engineers, but the engineers then have to add the new image to their Resources manually.
Image folder on DB, link folder under Resources - Same as above, but we add the folder under Resources, not the image files. However, the manual process of adding newly added images still remain.
What are the best practices you have followed?
Have you tried adding a Folder Reference instead of a group when adding it to your project and using DropBox to keep that folder up to date with your images ?
As a Folder Reference, it should always reflect the current state of the linked folder without the need to manually add each file as it is downloaded from DB.
After running a quick test, I found that adding Folder References and trying to use the images from there with [UIImage imageNamed:#"fileName.png"] doesn't find the actual image.
You have to actually include the relative path to your Folder Reference, like this:
UIImage * imageFromFolderReference = [UIImage imageNamed:#"FolderReferenceName/fileName.png"];
That seemed to do the trick.

Resources