Richlewis
Richlewis

Reputation: 15394

Asset Pipeline Rails 3

Im just looking for a little clarity to better my understanding of the Rails asset pipeline. I have placed my stylesheets and javascripts within app/assets/javascripts and app/assets/stylesheets. Now i am trying to get these views to render on my page but so far nothing is showing.. I wanted to see if someone could confirm if the following looks correct

In my layouts/application i have

 <%= stylesheet_link_tag "fullcalendar" %>
 <%= stylesheet_link_tag "application" %>
 <%= javascript_include_tag "jquery.js" %>
 <%= javascript_include_tag "jquery.rest.js" %>
 <%= javascript_include_tag "rails.js" %>
 <%= javascript_include_tag "application.js" %>

 <!-- these are needed for the calendar. -->
 <%= javascript_include_tag "jquery-ui-1.8.11.custom.min.js" %>
 <%= javascript_include_tag "fullcalendar.js" %>
 <%= javascript_include_tag "calendar.js" %>

And my index.html.erb looks like

<html>
<head>

<link href="/stylesheets/fullcalendar.css" media="screen" rel="stylesheet" type="text/css" />
<script type='text/javascript' src='/javascripts/jquery.js'></script>
<script type='text/javascript' src='/javascripts/fullcalendar.js'></script>
<script type='text/javascript' src='/javascripts/calendar.js'></script>
<script type='text/javascript' src='/javascripts/jquery-ui-1.8.9.custom.min.js'></script>
<script type='text/javascript' src='/javascripts/jquery.rest.js'></script>

Am I missing something or just being a real novice ( All constructive criticism welcome)

Upvotes: 4

Views: 646

Answers (2)

Sandro L
Sandro L

Reputation: 1160

You can see a quick overview in Ryan Bates Video: #279 Understanding the Asset Pipeline. For more info go to the RailsGuide: Asset Pipeline.

Both helped me a lot.

Upvotes: 1

Said Kaldybaev
Said Kaldybaev

Reputation: 10002

in Your layouts/application you just need this:

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

and in app/assets/stylesheets/application.css you just need:

   *=require_self
   *=require_tree .

and in app/assets/javascripts/application.js

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

And there's o need to include all the files

You'll have some problems in production if you include js files, to avoid it, you should add such files, ex: "fullcalendar.js" in config/production.rb, config.assets.precompile += %W(fullcalendar.js), and then run rake asset:precompile

Upvotes: 4

Related Questions