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

  • SEARCH
  • Home
  • 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 5964599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:27:43+00:00 2026-05-22T19:27:43+00:00

I have the following route definition: resources :documents do collection do post :filter end

  • 0

I have the following route definition:

resources :documents do
  collection do
    post :filter
  end
end

and the following model structure:

class Document < ActiveRecord::Base
  belongs_to :documentable, :polymorphic => true
end

class User < ActiveRecord::Base
  has_many :documents, :as => :documentable
end

and controller structure:

class DocumentsController < ApplicationController
  def index
    # not important
  end

  def filter
    # not important
  end
end

I can easily in a view say:

polymorphic_path([@user, Document])

to get the path /users/1/documents, but I want to be able to say:

filter_polymorphic_path([@user, Document])

to get the path /users/1/documents/filter, unfortunately, this doesn’t work.

Anyone know how I can pull this off without adding the following to my routes, for each of my documentable models:

resources :users do
  resources :documents do
    collection do
      post :filter
    end
  end
end
  • 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-22T19:27:44+00:00Added an answer on May 22, 2026 at 7:27 pm

    polymorphic_path([@user, Document], :action => 'filter') gives you /users/:user_id/documents/filter.

    Also, polymorphic_path([@user, Document], :action => 'filter', :sort_order => 'this-order') gives you /users/:user_id/documents/filter?sort_order=this-order.

    I ran into the same problem thinking you can replace the edit in edit_polymorphic_path to whatever method you want.

    See: http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following route definition in a MapRoute Table: routes.MapRoute( ViewDocument, browse/document/{document_id}/{document_title}, new
I have the following markup: <div id=routes> <ul id=routesList> <li class=routes>Route 1</li> <li class=routes>Route
I have the following route map.resource :account, :controller => users map.resources :users and /account/new
I have the following route in my bootstrap: Route::set('cycleadmin', '(<lang>/)cycleadmin(/<model>(/<action>(/<id>)))', array( 'lang' => $lang_options,
I have the following route in routes.rb : map.resources 'protégés', :controller => 'Proteges', :only
I have the following controller/route definition in Node.js (using Express and Mongoose). What would
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have the following route's defined: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(

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.