I'm currently having a slight problem referencing images in a Rails app which is then deployed to Heroku.
I have an image in the following path relative to the app:
app/assets/images/some-image.png
And I have referenced it in the HTML correctly (as far as I am aware):
<div id="main-nav" class="collapse navbar-collapse">
<img src="/assets/some-image.png" height="67"/><!-- **IMAGE SOURCE LINK** -->
<ul class="nav navbar-nav" id="mainNav">
<li class="active">Home</li>
<li>APR</li>
<li>Initiatives</li>
</ul>
</div>
Yet, this is what is displayed:
Does anyone have any ideas why this is happening?
You should use image_tag:
<%= image_tag "some-image.png", height: "67" %>
When you deploy to heroku, your assets will get compiled with a unique digest so you can't hard-code the reference to /assets/some-image.png. Check out "Rails Asset Pipeline on Heroku Cedar".
You will need to use some helper functions so the image path is correctly resolved, like image_path('my_image.png'). See "ActionView::Helpers::AssetTagHelper" or "Asset Tag Helpers".
Related
I'm developing an ASP MVC application with ScrollSpy on one of my pages. I'm having a strange problem where it's working correctly when I run my site from localhost, but when I publish the application to a server, ScrollSpy isn't adding the active class to the <li> items.
This is the script on my page which initializes ScrollSpy.
#section scripts
{
<script>
$(document).ready(function () {
$('body').attr("data-target", "#side-nav");
$('body').attr("data-spy", "scroll");
});
</script>
}
Here's how my ScrollSpy navigation is defined.
<div id="side-nav" class="pull-left">
<ul class="affix nav nav-list nav-pills nav-stacked">
<li>First Section</li>
<li>Second Section</li>
<li>Third Section</li>
</ul>
</div>
Each section has an anchor tag defined like this
<a class="anchor" id="first-section"></a>
I verified that jquery.js and bootstrap.js are referenced correctly on the server by going to View Page Source and clicking on the link to view the .js file. I tried replacing the .min versions of the files with the same .js file that's being used on localhost, but that doesn't work.
I apologize in advance for this being a difficult to recreate problem. Please tell me if I should post any additional data to make it easier to troubleshoot.
I'm new to Ruby on Rails, and have been battling with this issue for a while now.
I have pulled a website from git, and made sure all the dependencies are installed, however, when I run the site, I get the error:
ActionView::Template::Error ("\xA9" on UTF-8)
because of the line linking images using the code image_path("bground2.jpg").
When I remove the image_path("bground2.jpg"), the error is resolved.
I however need image_path("bground2.jpg") and can't do without it.
I have tried the solutions here, but it seems not to work
This is a section of the index.html.erb file, but the error is recurring over all places containing the image_path and image_url:
<%= provide(:title, 'Home') %>
<section id="slider" class="">
<div class="img-responsive" style="background-image: url(<%= image_path("bground2.jpg") %>); background-position: 50% 0;height: 500px;">
<div class="container clearfix">
<!-- <div class="slider-caption slider-caption-center">
<!-- <div class="banner heading-block title-center nobottomborder">
<h1><%= "#{t('.reach_home')}" %></h1>
</div> -->
So, I solved this by reinstalling the Ruby application.
Don't know what had caused it, but I just reinstalled the application and everything works fine.
Thanks all for the help.
I had this very same issue. I identified it to a file I had in my application, actually it was taking place in minified javascript file I had in my Rails app. I open the file in text editor, added a new line and, set the encoding as UTF-8 and saved it, and the problem disappeared.
I am trying to implement ui-routing in my rails application but it is not able to find the page to which I want to route to.
The tree structure in rails that I followed is
app
assets
javascripts
angular_controllers
menu_controller.js
config
menu_config.js
templates
login.html
code for menu_config.js
angular.module('publishingApp')
.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider) {
$stateProvider
.state('login',
{
url: '/login',
templateUrl: 'templates/login.html'
})
}]);
code for index.html
<div ng-controller="menuController">
<header ng-class="navClass">
<nav><img src="assets/sample_image.png"/>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li><a ui-sref="login">Signin</a></li>
<li>Signup</li>
</ul></nav>
</header>
<section>
<div ui-view></div>
</section>
Error which I received when I run the code on browser and click on signin menu option
GET http://localhost:3000/templates/login.html 404 (Not Found)
Now I know am doing something wrong and I don't understand how to configure rails to load the html page.
Please any help is appreciated..
Update:
I created a template folder inside public folder and removed the template folder from the app/assets/ and now everything works fine. So which way is a better way to create applications and which way should be followed?
I am trying to include an image in my web application but it is not showing up properly on my browser(localhost:3000). Have I set it up wrongly?
This is my view code:
<div class="row">
<div class="col-sm-4">
<img src="assets/img/Lab Potion.png" alt="#" class="img-responsive">
<h2>random text</h2>
<p>random text</p>
</div>
</div>
I downloaded an image and saved it under:
-Desktop
-rails_projects
-project_name
-app
-assets
-images
When I check in the images folder there is a file named Lab Potion.png and a bunch of random numbers inside(fingerprint?)
Why is the image not showing up?
<%= image_tag('Lab_Potion.png', :style => "z-index:19; position: relative; float: right;") %> will work. get rid of the space in the file name too, if not just for my sanity.
The random numbers are like a security feature and on each precompile the numbers end up changing. It's more complicated than that, but that is the gist.
And lastly, i doubt you have a img folder as well.
I'm trying to get a photo URL but I get a 'no allowed' error message.
The URL comes like C:\\upload\images, but on chrome it looks like like C://upload/images.
How can I solve this problem?
#foreach (Product pro in Model.Products)
{
<div class="col-lg-4 col-md-6">
<div class="single-product">`enter code here`
<img class="img-fluid" src="#pro.ThumpNailPicture" alt="">
<div class="product-details">
<h6>
#pro.Name
</h6>
I'm not quite sure what you are asking, but in general it is best to serve content over HTTP rather than directly from local disk. This can be done either via the wwwroot folder or a dedicated static content server.