Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:34:31+00:00 2026-05-25T20:34:31+00:00

So I have a resource type Post, that can be associated with a resource

  • 0

So I have a resource type Post, that can be associated with a resource of type Category. I have the following in my routes.rb file:

resources "code", :controller => :posts, :as => :code
resources "sports", :controller => :posts, :as => :sports
resources "gaming", :controller => :posts, :as => :gaming
resources "personal", :controller => :posts, :as => :personal

So this gives me the desired effect of accessing particular categories through a friendly URL, like http://host.domain/sports, and that will collect all the posts with a category of sports. However, I’m not entirely sure how to scope those resources to be particular to individual categories. I suppose I could do something like:

match ":category_name", :to => posts#index

But that is problematic because it will catch everything.

So I guess in summary what I’m looking for is to maintain friendly URLs (of the exact structure I’ve specified) for accessing posts with a particular category. Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:34:32+00:00Added an answer on May 25, 2026 at 8:34 pm

    You have a number of resources, should be accessible per each own url. Four of resources are the same type and can be determine as posts. It’s ok to provide their functionality by one controller and it’s easy to detect the current path, then parse and add number of active record scopes.

    But let’s look a little bit deeper. You have the same type of data, probably with same attributes, so the common pattern is “Single Table Inheritance”, it equal the one table and more models, the column “type” differs the models.

    Controllers are provide interface between user interaction and data flow, so I’d suggest you to use independent controller per each resource. It’s a general practice. If you don’t like to type more typical code, use Resourceful Controller plugin or so.

    Then you can have the structure:

    #routes
    resources :code, sports, :gaming, :personal
    
    # STI parent and children models
      model Post < ActiveRecord::Base
      model Sport < Post
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ControlTemplate for a WPF TabItem: <ControlTemplate x:Key=DefaultTabItemTemplate TargetType={x:Type TabItem}> <ControlTemplate.Resources>
I have couple resource DLLs that I currently load when application starts using following
I have a ComponentResourceKey defined in my resource dictionary like this: <Style x:Key={ComponentResourceKey TypeInTargetAssembly={x:Type
I have this mapper defined: mapper(Resource, resource_table, properties = {'type' : relation(ResourceType,lazy = False),
I have resource dictionary files (MenuTemplate.xaml, ButtonTemplate.xaml, etc) that I want to use in
I have a resource handler that is Response.WriteFile(fileName) based on a parameter passed through
I have my resource and they typical overridden method to handle POST requests. public
I have a resource file named filetypes.resx. Some how I figured out to bind
I have the following data that basically I only need a few bits of
I have a page that collects information on two objects of the same type.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.