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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:09:11+00:00 2026-05-22T02:09:11+00:00

I have a project where an User can own a Project and make part

  • 0

I have a project where an User can own a Project and make part of a Project as a Team.

My models are like that:

class User
 has_many :projects, :foreign_key => "owner_id"
 has_many :project_memberships, :foreign_key => "member_id"
 has_many :shared_projects, :class_name => "Project", :through => :project_memberships, :foreign_key => "member_id"
end

class Project
 belongs_to :owner, :class_name => "User"
 has_many :project_memberships
 has_many :members, :class_name => "User", :through => "project_memberships", :foreign_key => "member_id"
end

My question is: How can I create/delete etc a new Project so an User can own it since I’m not using nested resources?

Here is my Project Controller:

def new
@project = Project.new
end

def create
@owner = User.find(params[:user_id])
@project= @owner.projects.build(params[:project])   
    ...
end

Thanks in advance.

  • 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-22T02:09:12+00:00Added an answer on May 22, 2026 at 2:09 am

    If I understand your question correctly, you need to store current signed in user ID in session or use some authentication gem (like devise) which will do it for you.

    Devise provides helper method current_user which returns an instance of User model. So you could do like so:

    def create
    @project= current_user.projects.build(params[:project])   
        ...
    end
    

    Update
    If you pass user_id through form, you allow anyone to create project with another user’s id. Actions that create something, that belong to current user should be constrained to current user on the serverside

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

Sidebar

Related Questions

I have a Winforms project with a bunch of User controls. I'd like the
I have a project that I would like to start beta testing soon, it
I have a Qt/C++ project and an old VB6 project. The user base might
I have a feature which allows the user to create projects and view it
I have project that I'm working on that is going to require a webserver.
I have a project that I'm currently working on but it currently only supports
I have a project where I would like to generate a report export in
I have a .NET server application that must store passwords that can't be hashed
I have QGraphicsTextItem objects on a QGraphicsScene . The user can scale the QGraphicsTextItem
I have recently started a new C++ project and I intend to make it

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.