Alina
Alina

Reputation: 2261

Ruby on Rails, javascripts conflicts

I am using this example for file uploader and highcharts application in ruby. In order to get charts work, I had to add following files to my app/assets/javascript:

highcharts.js
jquery-1.4.2.min.js
rais.js

And to my charts.html.erb following code:

    <%= stylesheet_link_tag "application" %>
    <%= javascript_include_tag "jquery-1.4.2.min", "rails", "highcharts" %>
    <%= csrf_meta_tag %>

My charts look beautiful but I cannot upload the files. There is some kind of a conflict between those javascripts and etc. I want to move those 3 files to another directory and define a path for the code in charts.html.erb to that it will find where all neccessary files are.

I do not know where to write a defined path in the code. something like this:

    <%= stylesheet_link_tag "application" %>
    <%= javascript_include_tag "public/javascripts/jquery-1.4.2.min", "public/javascripts/rails", "public/javascripts/highcharts" %>
    <%= csrf_meta_tag %>

but it tells me an error in a console:

Started GET "/assets/public/javascripts/rails.js" for 127.0.0.1 at 2013-01-15 16:21:19 +0100
Served asset /public/javascripts/rails.js - 404 Not Found (33ms)

ActionController::RoutingError (No route matches [GET] "/assets/public/javascripts/rails.js")

:

Thanks in advance

Upvotes: 0

Views: 491

Answers (2)

alex
alex

Reputation: 3742

Answering your question: you can define your own path for assets (but it's not recommended), just add slash before the path. Like <%= javascript_include_tag "/public/javascripts/jquery-1.4.2.min.js", "/public/javascripts/rails.js", "/public/javascripts/highcharts.js" %>

Upvotes: 0

sjain
sjain

Reputation: 23344

You don't need to define each and every javascript file name explicitly in latest rails versions.

This is because of application.js file which requires every js for you in tree form.

//= require jquery
//= require jquery_ujs
//= require_tree .

You just need to do like that -

<%= stylesheet_link_tag    "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>

Upvotes: 2

Related Questions