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 8869979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:36:37+00:00 2026-06-14T17:36:37+00:00

I am using nested resources as shown below, but I now need the ability

  • 0

I am using nested resources as shown below, but I now need the ability to send in a date range parameter for paginating/filtering. I know the rule about no more than 1 nested resource, but I am not sure the proper way to apply a third variable to a route.

resources :projects do
    resources :expenses
end

Should I just craft my own match statement, like:

  match '/projects/:project_id/expenses/date/:start_date' => 'expenses#index', :as => 'view_expenses'

and then remove the nested resource?

I am concerned about sending a query string along, that I will have to somehow re-include it in all my paths, so I am guessing its something best handled with a route.

Just not sure if I am on the right track.

Thanks!

  • 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-06-14T17:36:39+00:00Added an answer on June 14, 2026 at 5:36 pm

    I think you would want to pass the date to the controller through a params hash. You could do this without having to mess with your paths. I’m not sure how you’re filtering the dates, but let’s say on your Expenses index page you have a search form that lets you filter by month and year.

    The search form would look something like:

    <%= form_tag(project_expenses_path(@project) do %>
      <%= label_tag(:search_date, "Search:") %>
      <%= date_select("expense", "date", :discard_day => true %>
      <%= submit_tag("Find") %>
    <% end %>
    

    Then your Expense controller would look like:

    class ExpensesController < ApplicationController
        def index
          @project = Project.find(params[:id])
          @expenses = #find the expenses by querying the db using params[:expense][:date]
        end
     end
    

    You will of course want some default date range so that you don’t get an exception when no date params are passed.

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

Sidebar

Related Questions

So I finally got my urls to work using nested resources but there's still
I'm developing a single-page view for a resource that contains multiple nested resources. Using
I'm using the friendly_id gem. I also have my routes nested: # config/routes.rb map.resources
I'm having trouble with and RSpec view test. I'm using nested resources and the
Can someone please point me towards some nice resources for understanding and using nested
Hi this is my first time using nested resources. I did rake routes and
I am using nested routes in my application (rails 3.2) as follows: resources :networks
I have nested resources with 2 models - products and product_images. I'm using Carrierwave
If you came across some C# code like this with nested using statements/resources: using
My environment: Rails 3.2 with draper gem I'm using nested resources and having trouble

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.