Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Is there a Treehouse course that goes over using Javascript with a Ruby on Rails app?

I'm about to start my own Rails project but I'm going to be using the jQuery Datepicker. How can I add this into my Rails app?

6 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya there! I'd suggest you to use asset pipelining instead of overloading public folder with different JS/images/CSS files. Asset pipelining compresses all your assets into one compressed file when your application goes into production environment. All your assets lives under your_project_name/app/assets. And eventually after compressing, the fingerprints get assigned to the compressed asset and it lives under public folder.

Rails create .coffee and .scss files for you at the time when controller gets generated. But if you want to switch to normal .css and .js extensions instead of server side preprocessors, you're gonna have to change their extensions manually and mention 'em in manifest files in the order you want your files to get compressed to a fingerprint in production environment.

Check out this great article on Asset Pipelining.

Ari Misha
Ari Misha
19,323 Points

@BryanReed you could also include many front end frameworks like react or angular in your project. Just mention their respective gems in your gemfile and do bundle install and you're good to go. (:

Michael Hulet
Michael Hulet
47,913 Points

Front-end JavaScript/jQuery is totally agnostic of your backend language/framework. You can include it in the proper place in your Rails template as if it were regular HTML, and it should work just fine

What do you mean by 'proper place in your Rails template' exactly?

Michael Hulet
Michael Hulet
47,913 Points

Wherever it is in your ERB template that you're including your JavaScript. Usually, this is right before the closing </body> tag

Got it! Wanted to make sure there wasn't a conventional way to do so that I was missing!

Michael Hulet
Michael Hulet
47,913 Points

Great! If you have any more trouble, RailsCasts did a couple of walkthrough videos on using the jQuery UI Date Picker in a Rails form:

What about an 'Asset Pipeline' in a Rails app? When would one use that instead of just calling the scripts as needed inside the HTML?

Michael Hulet
Michael Hulet
47,913 Points

That's a great question, and one I'm afraid I don't know the answer to. I used Rails a couple times a few years ago, but I don't have experience in it outside of that. Personally, I'm mainly an iOS developer. I'll see if someone more qualified than I can take a look at this question, though it might take a bit, because it's the weekend

Michael Hulet
Michael Hulet
47,913 Points

In the meantime, you can check out this gem that claims to package the jQuery UI Date Picker for the Rails Asset Pipeline

Thanks man! I'm definitely gonna check out those videos too!

Michael Hulet
Michael Hulet
47,913 Points

No problem! I'm glad I could help :)