Can't access the image through data-image property - ruby-on-rails

I am facing trouble with this div element during loading the image. 404(Not Found)
<div class="sidebar" data-color="purple" data-background-color="white" data-image="../assets/img/sidebar-1.jpg"></div>
Here is my code in Views. I am not familiar with this data-image tag. I have kept "sidebar-1.jpg" image inside my app/assets/images folder.
Now how can I solve this error and get the image works without harming other attributes(data-color, data-background) of this div element?
Plz help me

The path should be /assets/sidebar-1.jpg
Hope it work.

Related

How to reference image in data attribute within Rails 5

i'm new on Rails. I can use images with image_tag or image_path.
But , i have an html template and these methods does not work in data-attributes. In my html , there is a data-background attribute which changes background of the div.
My html :
<section id="sub-header" class="section bg-parallax pt-0 pb-0" data-background="<%= image_path('bg/about.jpg') %>">
This directory is under the app/assets/images/bg. But i can't reach the image.
Where should i put these images ? and how can i reach images in this example
Try this workaround :
data-background=<%=Rails.root.to_s + "path_to_your_image" %>
I know it' ugly :/
I tried all combinations. But solution was simple. You don't need to use rails helper functions for that. I moved my images from assets to public folder and :
<section id="sub-header" class="section bg-parallax pt-0 pb-0" style='background:url("/bg/about.jpg")'>

photoswipe: passing HTML file instead of image

I would like to use the same set up as Photoswipe, only pass a div or index.html through instead of an image.
Here is the link to the photoswipe package:
http://www.photoswipe.com
Please let me know if this isn't possible! Thank you!
Since you use get method to load more images you can get html instead of images.
Just you need to print html as you require in your ajax request. And then you can display the html by using javascript i.e when you get html in your data variable.

Display image using JSF from tomcat folder

Hi I am trying to display image which I have stored in my tomcat's webapps folder
i.e(/webapps/test_Proj/images)
in this way.
<h:graphicImage value="/images/#{backBean.obj.image}" />
When I am trying to see it in Mozilla debug mode, it's showing me error as
'failed to load given url'
it is also showing correct path as
/test_proj/images/sample.png
where my images are stored
What I am missing here ?
How should I overcome with this problem?
Not sure if this has to be called dirty work or a hack... but it works :)
In server.xml, place the below content.
<Context path="/YourContextName/images" docBase="D:/Servers/Tomcat/images" />
For eg., I have created HelloWorld.war. So for YourContextName I have given the value HelloWorld.
I have placed all my images which I want to render under D:/Servers/Tomcat/images.
When you start your server, make sure you can access your images by typing below path.
http://localhost:8080/HelloWorld/images/SampleScreenShot.JPG
And finally in your facelets page,
<h:graphicImage value="/images/SampleScreenShot.JPG"></h:graphicImage>
Remember Context path is added automatically. So above code would result in
http://localhost:8080/HelloWorld/images/SampleScreenShot.JPG

Rotativa / Wkhtmltopdf images not displaying

I am currently creating an MVC 4 web application.
I have an action that has a base background image which is always the same then an arrow image which changes in degrees depending on the information that is collected within the action.
I call this action using
<img src="#Url.Action("trend-image", "NonReg_Reports")" alt="background" width="245" height="105" />
This works fine when it is called and is just displaying a HTML webpage. It gives me the HTML.
<img src="/nonreg-report/01495344/trend-image" alt="background" width="245" height="105">
I am then using Rotativa / Wkhtmltopdf to convert this HTML page into a PDF. This runs the same piece of code as above.
The problem is I am just getting a white box with the alternative text in it if I use the code above.
If I use <img src="~/Content/images/trend_back_medium.png" alt="astuff" /> which is the actual background image in my project it works fine.
The image from the code above can not be saved anywhere due to how it is used. I am thinking that it is a path problem, but after trying lots of different things I can still not get it to work.
Any suggestions or help would be greatly appreciated Thank you.
I had the same problem. Normal html view was ok with pictures, pdf was not display it. I used Server.MapPath to point to picture and it was ok...
<img src="#Server.MapPath("~/Folder/SubFolder/Subfolder/ImageName.png")" />
I hope this will help
Adam
I faced the same problem and I found a workaround, not a nice one, but it suits my needs.
It seems that Rotativa(Wkhtmltopdf?) have a problem with images which are returned from http handler (at least my case). So to handle this situation, in controller action before return new ViewAsPdf... my code manually save file to some local 'temp' folder and replace 'src' of images in rendered view with paths to that local files in server path manner, eg: http://localhost/img/temp/trend-image.png.
This is not a nice solution, if you already found better one, let me know.
Adding the attribute [System.Web.Mvc.AllowAnonymous] to the controller method returning the image solved the problem for me.
It seems to work okay via css...
I was trying to display a logo at the top of the page and switched it with a div and set the height and width to that of the image.
CSS:
div.logo {
background-image: url("/images/logo/logo.png");
height: 53px;
width: 185px;
}
HTML:
<div class="logo"></div>
I found that with my pages, the images were not showing because they were .gif files.
Rotativa can have problems with gifs.
When I changed the images to .jpg or .png everything worked well.
I think it might come down to basically the ".png" bit being missing.
You could add a mapping like this /nonreg-report/01495344/trend-image.png ยป /nonreg-report/01495344/trend-image and have both of the urls active, why not? That way wkhtmltopdf is fooled and you still have your dynamic image without saving it anywhere on disk. Dynamic urls can work, I do that for live-converting gif2png for wkhtmltopdf.
Also it might help to have an absolute url, which I think you can do with something like this:
src="#Url.Action("trend-image", "NonReg_Reports", null, Request.Url.Scheme)"
If you are specifiying height and width then make sure you should write it in style tag
like <some-tag style="height: 100px; width:100px">

How do change img src.value for upload new image

this code isnt work
anyone know how ?
I would suggest using http://jquery.com/ as it provides many function to do things like this, but using CSS style selectors instead of the nasty javascript dom.

Resources