Working with javascript in a view in ruby on rails -
alright guys, ruby noobie here, , find myself in unfortunate situation moving project on django ruby on rails. first things first, setting application.html.erb file, , cannot seem javascript working. images , css coming through, not javascript. there javascript files within assets directory , within application.html.erb file. neither coming through.
all of images, css, , javascripts located within respective directories in app/assets/.
my application.html.erb file head tag:
<!doctype html> <html> <head> <!--[if lt ie 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <title>the atmosphere</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel="shortcut icon" type="image/x-icon" href="/assets/atmosphere_favicon.png"> <link rel="stylesheet" type="text/css" href="/assets/style.css"> <link rel="stylesheet" type="text/css" href="/assets/profile.css"> <link rel="stylesheet" type="text/css" href="/assets/advanced-slider-base.css"> <link rel="stylesheet" type="text/css" href="/assets/small-round-button.css"> <link rel="stylesheet" media="all" href="/assets/hover.css"> <script type="text/javascript" src="/assets/jquery-1.7.2.min.js" charset="utf-8"></script> <script type="text/javascript" src="/assets/jquery-ui.js" charset="utf-8"></script> <script type="text/javascript" src="/assets/scroll.min.js"></script> <!--<script type="text/javascript" src="js/jquery.transition.min.js"></script>--> <script type="text/javascript" src="/assets/jquery.touchswipe.min.js"></script> <script type="text/javascript" src="/assets/jquery.easing.1.3.min.js"></script> <script type="text/javascript" src="/assets/jquery.advancedslider.min.js"></script> <script type="text/javascript" src="/assets/simplyscroll.js" charset="utf-8"></script> <script type="text/javascript" src="/assets/jquery.marquee.js"></script> <script type="text/javascript" src="/assets/jquery.pause.min.js"></script> <script type="text/javascript" src="/assets/jquery.webticker.js"></script> <script type="text/javascript" src="/assets/engine.js" charset="utf-8"></script> <script type="text/javascript" src="/assets/jquery.jplayer.min.js"></script> <script type="text/javascript" src="/assets/jquery.cookie.js"></script> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <!-- start soundmanager2 --> <!-- demo, make fonts nicer etc. --> <!-- soundmanager.useflashblock: related css --> <link rel="stylesheet" type="text/css" href="/assets/flashblock.css" /> <!-- soundmanager required --> <link rel="stylesheet" type="text/css" href="/assets/360player.css" /> <link rel="stylesheet" type="text/css" href="/assets/360player-visualization.css" /> <!-- sound manager apache-licensed animation library --> <script type="text/javascript" src="/assets/berniecode-animator.js"></script> <!-- soundmanager core stuff --> <script type="text/javascript" src="/assets/soundmanager2.js"></script> <script type="text/javascript" src="/assets/360player.js"></script> </head>
the javascript in question within application.html.erb file between 2 script tags right before body closing body tag. it's quite lengthy omitted time being.
i understand ror has conventions far asset pipeline, , i'm assuming i'm missing ruby syntax here, used referencing file paths , having working. also, there ruby syntax required within view make javascript within application.html.erb function? right referenced as:
<body> . . <script> . . . </script> </body> </html>
thanks guys! appreciated.
my application.js file:
// manifest file that'll compiled application.js, include files // listed below. // // javascript/coffee file within directory, lib/assets/javascripts, vendor/assets/javascripts, // or plugin's vendor/assets/javascripts directory can referenced here using relative path. // // it's not advisable add code directly here, if do, it'll appear @ bottom of // compiled file. // // read sprockets readme (https://github.com/rails/sprockets#sprockets-directives) details // supported directives. // //= require jquery //= require jquery_ujs //= require turbolinks //= require_tree .
application.css file:
/* * manifest file that'll compiled application.css, include files * listed below. * * css , scss file within directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or plugin's vendor/assets/stylesheets directory can referenced here using relative path. * * you're free add application-wide styles file , they'll appear @ bottom of * compiled file styles add here take precedence on styles defined in styles * defined in other css/scss files in directory. better create new * file per style scope. * *= require_tree . *= require_self */
the railsy way of including javascript use:
<%= javascript_include_tag( 'your_script' ) %>
more docs here: http://apidock.com/rails/actionview/helpers/assettaghelper/javascript_include_tag
application.js list of files precompiled asset pipeline, can include scripts there well, if want add script particular view, way go.
Comments
Post a Comment