3

I know you can add jQuery and bootstrap with gems, assets, and the application.css and application.js file. However, I would like to be able to add these files through a CDN.

<link rel="stylesheet"             href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

I have added the above into my application.html.erb file, but I seem to not be able to use bootstrap or jQuery still. Can you please explain why rails doesn't allow linking in the html file? Why must we use gems?

kchow
  • 63
  • 2
  • 6
  • That is a CDN. https://maxCDN.bootstrapCDN.com - I don't think they are lying. Alternatively you could place the files on a CDN of your choosing and load it from there. – errata May 20 '15 at 18:31
  • Yes but the CDN is not working. There is no effect on the rails app. Does rails allow CDNs in the html files or must I use gems and require that js file in the application.js? – kchow May 20 '15 at 18:36
  • I just tried it and it is now working again. I'm a little confused but thanks so much! – kchow May 20 '15 at 18:47
  • Look at the answer below. Are you not seeing any bootstrap files included? View the source of your app from a browser and make sure it's not loading. – errata May 20 '15 at 18:49

3 Answers3

2

You need to add the js file before the closing body tag as well:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
Sharvy Ahmed
  • 7,247
  • 1
  • 33
  • 46
0

I guess you have to make sure you call your Jquery before your bootstrap files

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

If you want to do a cdn call back for both Jquery and Bootstrap these are the links: stackoverflow - Bootstrap cdn callback and stackoverflow - Jquery cdn callback

Community
  • 1
  • 1
Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
0

Use the jquery cdn gem

In your layout,

<%= include_jquery cdn: :google %>
tangrufus
  • 357
  • 2
  • 13