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?

4
  • That is a CDN. 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. Commented May 20, 2015 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? Commented May 20, 2015 at 18:36
  • I just tried it and it is now working again. I'm a little confused but thanks so much! Commented May 20, 2015 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. Commented May 20, 2015 at 18:49

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

Use the jquery cdn gem

In your layout,

<%= include_jquery cdn: :google %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.