Canna
Canna

Reputation: 3794

Importing css or javascript path issue in Rails

enter image description here

This is the structure, and i want to import javascript and css in fancybox folder.

So i added a code like this,

<link rel="stylesheet" type="text/css" media="all" href="/app/assets/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="/app/assets/fancybox/jquery.fancybox.js?v=2.0.6"></script>

and it throws these errors,

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/app/assets/fancybox/jquery.fancybox.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/app/assets/fancybox/jquery.fancybox.js?v=2.0.6

Do i have to use, rails code?

like somekind of this?

<%= javascript_include_tag "application" %>

I'm not used to rails code, so i used original html codes. I think that is the problem, but i'm not sure how to add the path in here.

Upvotes: 2

Views: 125

Answers (1)

Maur&#237;cio Linhares
Maur&#237;cio Linhares

Reputation: 40333

Yes, the issue is at the use of HTML, as your assets are inside the assets directory, you need to serve them using the rails asset pipeline. If you want to serve them directly without going through the asset pipeline (not really recommended, but you could do it) you would have to put them at the public directory of your app instead.

At your application.css you should include the references to the CSS files (once you open it you will see examples of that) and you should do the same for your application.js file.

Upvotes: 1

Related Questions