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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:07:56+00:00 2026-06-12T17:07:56+00:00

I have a Client model, and nested in that, I have a Program model.

  • 0

I have a Client model, and nested in that, I have a Program model. Ex:

localhost:3000/clients/2
localhost:3000/clients/2/programs/5

In my ApplicationController class, I want to be able to load in the Client model object in the before_filter. I tried doing it like this:

@user_client = Client.find(params[:client_id])

This works for nested resources (localhost:3000/clients/2/programs/5) but it doesn’t work for the client realm (localhost:3000/clients/2). If I do it this way:

@user_client = Client.find(params[:id])

It’s the opposite – it works in the client realm (localhost:3000/clients/2) but not the nested resources (localhost:3000/clients/2/programs/5).

Is there a method that would work for both?

  • 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-12T17:07:58+00:00Added an answer on June 12, 2026 at 5:07 pm

    Could you do something like:

    @user_client = Client.find(params[:client_id] || params[:id])
    

    So that if one is nil then the other one will be entered as the id.

    Having them in this order means that it will always grab it if there is a :client_id.

    The dangerous item though is that the id at the end of the link is called :id so there could be some confusion there if you are trying to identify records. Just be vigilant.

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

Sidebar

Related Questions

In a client application I have a DBIx::Class model 'Todo' that can be linked
I have a Client and ProposalRequest model that look like this: class Client <
I currently have a client that wants me to 'abstract' out a domain model
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I know that the asp.net repeater doesnt have a Client side object model, and
I'm on Rails 3. I have a model Client that has an address_id .
I have a Client model that can have many Projects . These are my
I have a project model that has_many :tasks . I added a nested resource
Hello I have a model named Client which has nested models called Receiver and
Here is the situation. I have some ViewModels that contain nested complex model types.

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.