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

Do I need to use Javascript for this?

I have a Rails app with a Word model and a Category model. Words has_and_belongs_to_many Categories.

I have table which contains a list of Words and each Word has several Categories. Some of those Categories exist in more than one word.

I want to click on a Category and for that to make the wordlist list only those words with that Category. Can you give me a brief pointer towards what I need to do, because I suspect this can't be done just with pure Ruby, I think I'm gonna need something else, but I don't know what: Javascript I suspect? I've never done anything with Javascript.

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

If page refresh is OK, then you can simply have an index view with list of categories and when you click one, you get a show template that lists the words that fall under this category. If this needs to happen dynamically, only changing one part of the page (word list), then this would require javascript.

Yeah I had exactly the same thought, so it would be Javascript. Someone told me it would need to be Ajax? Basically, I want to learn how to get this done as quickly as possible, but I don't want someone to just write the code for me. So, my question is, exactly which Treehouse modules do you think I need to work through for the lightbulb to eventually switch on and I know how to do it?

I do apologize for offering to give you a solution to your problem, but there is going to be quite a bit to learn in order to your project in JavaScript. Start at the beginning with JavaScript Basics and then work your way up.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Unfortunately, I don't think Treehouse has a course for this. The Rails API course kinda touches on the topic, but I'm not sure if it's enough to inspire you.

You can learn the skills necessary to perform this kind of program by starting from the basics and building up. So, yes, Treehouse does have courses that can help you with this.

Hey Andrew,

I suspect that you can do this with Ruby (my Ruby knowledge is extremely limited though). But, this sounds like something that belongs in the JavaScript realm since you're going to be doing a lot of user interaction. And when you're doing a lot of user interaction, you want to use the user's PC for most of the interactivity (front-end/JavaScript) instead of the server for most of the interactivity (back-end/Ruby). If no one helps you with a short solution, then I will in the morning for sure.