Building a site similar to this?

As a side project I want to try and build a course site like Baserails to understand rails's architecture and routing more. The biggest problem that I'm coming across is how to set things up for instance, I would scaffold a courses page and then add courses, but how do I add links after the courses? For example, learnrails.com/courses/craigslist/1 , learnrails.com/courses/craigslist/2 , learnrails.com/courses/craigslist/3 , learnrails.com/courses/craigslist/4 . How do I create 1,2,3,4? or should I scaffold another cragislist?

Posted almost 5 years ago by Wilson
Posted almost 5 years ago by Alex Yang

Use the FriendlyId gem: https://github.com/norman/friendly_id. FriendlyId allows you to customize URLs based on the name of the object. For example, if you create a course called Craigslist, then instead of /courses/1, you'll see /courses/craigslist. Try it out!

1
Posted almost 5 years ago by Wilson

Hey Alex! Yea I'm familiar with friendly_id , but what I meant is how do I create a new page for each sections of a new course. For instance the craigslist course would have a video on "How to install rails", the next step will then be "How to set up your first app" and so on. Do I create a new page for each and just define it in the controller?

1
Posted almost 5 years ago by Alex Yang

You need to have a separate resource defined for each video. For example, you could have a video model nested inside the course model. That would give you the courses/craigslist/1 URL you're looking for.

1
Posted almost 5 years ago by Wilson

Right, but how would I add pages to that model?

1
Posted almost 5 years ago by Alex Yang

Each video would be a page. It would have its own URL and its own view page (e.g. views/videos/show.html.erb).

1
Posted almost 5 years ago by Wilson

Right, would i need to generate a scaffold for videos so that i can create a new page for each video?

1
Posted almost 5 years ago by Alex Yang

Yes, that's right. However, I'd recommend going through either the Etsydemo or Yelpdemo courses beginning-to-end before trying to do this. I'm all for learning by doing, but it sounds like it would really help you to get some more practice before trying to work with nested resources.

1
Posted almost 5 years ago by Wilson

Got it thanks! so for example, your yelpdemo course, would have a scaffold for courses and then you would scaffold again for a yelpdemo? Then customize the view for each page and add videos etc. to it correct?

1
Posted almost 5 years ago by Alex Yang

No, you would have a course scaffold and then a nested video scaffold. This approach is explained in the 'Link Reviews to Restaurants' and 'Nest Resource URLs' videos in the Yelpdemo course.

1