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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:33:38+00:00 2026-06-16T14:33:38+00:00

Let’s see if I can explain myself well enough about the doubts I have.

  • 0

Let’s see if I can explain myself well enough about the doubts I have.

I have a User model that is managed by Devise. So in my routes I have:

devise_for :users

In the User model, I have an association with the model Plan. The assocation is:

User has_many Plans
Plan belongs_to User

At this point I also have a resource for the Plan model, so I can fetch all the Plans, show a particular plan and so on. But I want to go further.

I want to be able to see plans of a particular User and let a particular User to see his own plans and edit them.

So, for example, whenever I go to:

/users/:id/plans

I want to be able to see the plans for that particular :id user. And if the user who is visiting that url is the one that is logged in, I want him to be able to edit those plans.

How can I manage all this behavior? Is there any gem out there that helps with it? Or I need to do conditionals in the views saying if current_user…

  • 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-16T14:33:39+00:00Added an answer on June 16, 2026 at 2:33 pm

    Let’s start with routes, you can make your routes like this:

    resources :users do
      resources :plans, only: [:index]
    end
    
    resources :plans, except: [:index]
    

    I used resources :plans inside resources :users to have route like this /users/:user_id/plans, while the resources :plans outside is for the rest of the actions (edit, destroy, …) that don’t require a user_id, i.e., a plan is identified by a unique id so you don’t need a user_id to fetch it from the db for editing or destroying.

    Now for the controller, we can make it like this:

    class PlansController < ApplicationController
      before_filter :is_plan_owner?, only: [:edit, :update]
    
      def index
        @plans = Plan.where(:user_id => params[:user_id])
      end
    
      def edit
        @plan = Plan.find(params[:id])
      end
    
      private
    
      def is_plan_owner?
        if current_user != Plan.find(params[:id]).user
          # Scream, shout, call 911 and/or redirect else where
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's see if I make myself clear. I have an old set of scripts
Let's say I have a method in java, which looks up a user in
Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say for a moment that I have the following module in python: class
Let's say I have some text as follows: do this, do that, then this,
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's suppose that we have multi-site CMS and every website in this CMS having
Let's say I have one class User, and it has a property of 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.